Matlab (modifications)

profilereevin
exam1_2.m

impe=rand(2,20); save('IMPEDANCE.txt','impe','-ASCII'); load('IMPEDANCE.txt'); %first load the text file that contains the impedance values %problem 1 finding column number Number_of_components=size(IMPEDANCE,1); %Problem 2 Impedance_Catesian=zeros(size(impedance)); %Initate the variable Impedance_Polar which contains magnitude and phase of impedance all components to zero real=impe*cos(atan(impedance(:,2)./impedance(:,1))); imaginary=atan(impedance(:,2)./impedance(:,1)); %Problem 3 Impedance_Catesian(:,1) = real; Impedance_Catesian(:,2) = imaginary; %Problem 4 save('Impedance_Catesian.txt','Impedance_Catesian','-ASCII'); %Problem 5 disp(['"There are ', num2str(Number_of_components), ' components in the file impedance.txt. The Conversion of CARTESIAN format of complex number into Polar is completed and the result is saved in Impedance_Cartesian.txt"']); %Problem 6 load('IMPEDANCE.txt'); %first load the text file that contains the impedance values Number_of_components=size(impedance,1); %The number of components=Number od rows in the variable 'impedance' Impedance_Polar=zeros(size(impedance)); %Initate the variable Impedance_Polar which contains magnitude and phase of impedance all components to zero real=zeros(Number_of_components,1); imaginary=zeros(Number_of_components,1); i=1; while(i<=Number_of_components) real(i,1)=sqrt(impedance(i,1)^2+impedance(i,2)^2); imaginary(i,1)=atan(impedance(i,2)/impedance(i,1)); i=i+1; end Impedance_Catesian(:,1) = real; Impedance_Catesian(:,2) = imaginary; save('Impedance_Catesian.txt','Impedance_Catesian','-ASCII'); disp(['"There are ', num2str(Number_of_components), ' components in the file impedance.txt. The Conversion of cartesian format of complex number into Polar is completed and the result is saved in Impedance_Polar.txt"']);