USE MATLAB. THE CONTENTS OF THE TEXT FILE IS BELOW THE PROBLEM JUST COPY AND PAS
ID: 2248865 • Letter: U
Question
USE MATLAB. THE CONTENTS OF THE TEXT FILE IS BELOW THE PROBLEM JUST COPY AND PASTE INTO A NOTEPAD AND RENAME IT impedance.txt
An engineer had measured impedances of a collection of electrical components and created a text file -
impedance.txt - based on the numerical data. The first
column of the file is real part of the impedance and the second column is the imaginary part of the
impedance. Row number indicates the number of components.
What you should do
Create m-file that
(1) will read the impedance.txt and find the row number (You can use ‘size’ function)
(2) compute magnitude and phase (angle) of impedance of individual component
(3) Save the result on a variable Impedance_Polar
(4) Save the result on a text file Impedance_Polar.txt
(5) Also have this following message displayed on the screen (“There are ### components in the
file impedance.txt. The Conversion of Cartesian format of complex number into Polar is completed and
the result is saved on Impedance_Polar.txt”)
(6) Do this with FOR LOOP and WHILE LOOP (in other words, create two script one with for loop
and one with while loop)
THE CONTENT OF THE TEXT
9 10
5 10
10 13
9 7
11 8
11 6
11 14
5 11
5 9
8 11
10 10
11 11
9 10
13 12
12 10
14 14
10 7
8 6
6 6
11 5
12 9
9 9
5 8
7 12
6 11
7 12
9 14
10 14
9 6
13 6
10 11
14 5
11 10
14 10
7 13
11 9
7 8
11 11
11 12
5 10
7 8
7 6
11 10
13 7
8 5
12 12
11 7
5 9
11 11
8 8
14 12
5 8
9 11
9 12
9 9
12 5
8 8
12 9
9 7
5 6
6 13
12 9
9 13
6 8
8 12
11 8
6 13
12 12
7 8
14 7
7 12
12 14
6 8
7 11
5 9
10 13
11 12
10 6
9 13
11 14
11 10
11 13
11 10
14 6
7 6
12 9
7 12
6 13
11 12
9 8
9 10
11 5
12 6
8 6
11 11
9 9
13 6
13 9
7 6
11 5
Explanation / Answer
clc
close all
clear all
% que-01: Reading the text file 'impedance.txt'
C=dlmread('impedance.txt');
[r,c]=size(C);
% que-2 : Magnitude and Phase of Collected data in C
img=C(:,1)+1i*C(:,2); % Data read from txt file converted to complex form
mag=abs(img); % Magnitude of complex values
phs=angle(img); % Phase of complex value
% que-3: Saved the result on variable 'impedance_Polar'
impedance_Polar=[mag phs];
% que-4: Save the variable 'impedance_Polar' to 'impedancePolar.txt' file
dlmwrite('impedance_Polar.txt',impedance_Polar,...
'delimiter',' ','precision',3)
% que-5: Displaying the number of components in impedance.txt file
fprintf(1,'There are %d components in the file impedance.txt.The Conversion of Cartesian format of complex number into Polar is completed and the result is saved on Impedance_Polar.txt',r);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.