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

 채택된 답변

Star Strider
Star Strider 2018년 11월 19일

1 개 추천

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.

댓글 수: 2

JJ
JJ 2018년 11월 19일
That worked. Thank you very much.
Star Strider
Star Strider 2018년 11월 19일
As always, my pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 11월 16일
편집: madhan ravi 2018년 11월 16일

0 개 추천

legend({'poles of sys_a','poles of sys_b'})

댓글 수: 6

JJ
JJ 2018년 11월 19일
Nope, doesn't work. It still displays a black cross where a red circle should appear in the legend.
madhan ravi
madhan ravi 2018년 11월 19일
provide your datas to test
Walter Roberson
Walter Roberson 2018년 11월 19일
When I try in R2018b, I get a legend with black x and red o
JJ
JJ 2018년 11월 19일
I'm using R2018b. But just black crosses.
madhan ravi
madhan ravi 2018년 11월 19일
Even am using 2018b I get the same result as sir Walter
JJ
JJ 2018년 11월 19일
I added the example, so the question is still open.

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

JJ
2018년 11월 16일

댓글:

2018년 11월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by