MATLAB: Create a legend for complex numbers plot

plotplotting

Hi,
I am plotting m by n matrices of complex numbers using
figure;
plot(poles_sys_a, 'kx'); hold on;
plot(poles_sys_b, 'ro'); hold off;
How can I insert a legend into that plot, that correctly labels the two sets?
legend('poles of sys_a','poles of sys_b');
doesn't work.
For example try
poles_sys_a = rand(3,10) + i*rand(3,10);
poles_sys_b = rand(3,1) + i*rand(3,1);
Thanks a lot.
JJ

Best Answer

Your ‘poles_sys_a’ matrix is confusing the plot function. If you create the ‘poles_sys_a’ matrix to vectors (using the ‘(:)’ notation), it works correctly with the legend call:
poles_sys_a = rand(3,4) + 1i*rand(3,4);
poles_sys_b = rand(3,1) + 1i*rand(3,1);
figure;
ha = plot(real(poles_sys_a(:)), imag(poles_sys_a(:)), 'kx');
hold on
hb = plot(real(poles_sys_b), imag(poles_sys_b), 'rx');
hold off
legend('poles of sys_a','poles of sys_b');
I decreased the size of ‘poles_sys_a’ so I could be certain it plots correctly with my changes. (It does.) I also changed the red 'o' to 'x' because by convention ‘x’ indicate pole locations, and ‘o’ zero locations.