Why Matlab is not plotting anything in my figure?

[EDIT: 200110710 16:40 CDT - reformat - WDR]
I wrote a program and want to plot Zr as a line connecting dots for every whole degree from 0 to 360 degrees or 2*pi radians. I am not seeing anything when I run the following program:
%-------------------------------------------------------------------------------------------------------------------------------------
clear , clc ;
m = 0.25; % locus of the impedance “seen” by relays
Z = input('impedance is 0.1i or 0.025 + 0.1i '); % constant impedance
Ea = 1; % set Ea at 1 Per-Unit for simplicity
Eb = Ea / input('voltage behind Zeq = Zm ratio is 1.15 or 0.87 ');
Zm = m * Z + (1 - m) * Z; % equivalent impedance
d = 0;
increment = pi / 180;
end_count = 2 * pi;
for d = 0: increment : end_count;
d; % values of d in radians
I = ( Ea * cos(d) + Ea * 1i * sin(d) - Eb ) / Z;
% current of the circuit
E = ( 1 - m ) * (Ea * cos(d) + Ea * sin(d) * 1i + m * Eb);
%Voltage seen by relay
Zr = E / I; % impedance seen by the relays at m
r = abs(Zr);
the = angle(Zr);
end
figure ( 1 );
set (gca, 'FontSize', 12)
whitebg('white')
polar (r, the, 'red'), grid on
xlabel ('Impedance, Zr, Seen By Relay [Per-Unit]','FontSize',14);
ylabel ('Polar Coordinates / Compass Plot','FontSize',14);

Answers (1)

Each time through the loop, you are overwriting "r" and "the", so at the end of the loop they have only scalar values and only a single point is being plotted.
You should consider vectorizing your loop, or you should learn how to use arrays and loop indices.

4 Comments

Thanks Walter. I googled info on vectorizing my loop and am trying to apply it to my program and still can't get it to work. In hindsight, I should've asked for suggestions in how to correct that part of my program. Can you show me how to fix it?
n=1;
for d = 0: increment : end_count;
d; % values of d in radians
I = ( Ea * cos(d) + Ea * 1i * sin(d) - Eb ) / Z;
% current of the circuit
E = ( 1 - m ) * (Ea * cos(d) + Ea * sin(d) * 1i + m * Eb);
%Voltage seen by relay
Zr = E / I; % impedance seen by the relays at m
r(n) = abs(Zr);
the(n) = angle(Zr);
n=n+1;
end
%work for you?
d = 0: increment : end_count;
I = ( Ea * cos(d) + Ea * 1i * sin(d) - Eb ) / Z;
E = ( 1 - m ) * (Ea * cos(d) + Ea * sin(d) * 1i + m * Eb);
Zr = E ./ I;
r = abs(Zr);
the = angle(Zr);
I'm getting the plot to work now. Thank you both for responding.

Sign in to comment.

Categories

Tags

Asked:

on 10 Jul 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!