How to draw a phasor diagram in MATLAB?
function [value] = drawPhasors(Z) %format bank | |
figure | |
hold on | |
Len = max(Z); | |
plot ([-Len, Len], [0,0]) %draw vertical line | |
plot ([0,0], [-Len, Len]) %draw horizontal line | |
axis ([-Len, Len,-Len, Len], 'square') %set axes | |
grid on | |
title('Phasor diagram') | |
xlabel('Real axis') | |
ylabel('Imaginary axis') | |
for k=1:length(Z) %for each number in array | |
myList = [real(Z(k)),imag(Z(k))]; | |
arrow([0,0],[real(Z(k)),imag(Z(k))]) %plot phasor | |
%str = sprintf('%f+ %fj', real(Z(k)),imag(Z(k))); | |
%text(real(Z(k)),imag(Z(k)),str) | |
end | |
end |
This function above takes an array of complex numbers and plots them on the Argand plane. Using multiple complex numbers it gives a phasor diagram.
The function drawPhasors uses Erik Johnson's arrow function. It can be downloaded here:
http://uk.mathworks.com/matlabcentral/fileexchange/278-arrow-m
I added Erik's function to my MATLAB path and I was able to use all of its nice properties.
Nincsenek megjegyzések:
Megjegyzés küldése