A simple issue with legend

조회 수: 15 (최근 30일)
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2023년 11월 17일
댓글: Mohammad Shojaei Arani 2023년 11월 17일
Hello,
I have a really simple question. To my surprise, I am could not help it (I have no idea !!!). When I type
x1=linspace(0,2*pi,1000);y1=sin(x1);y2=cos(x1);h1=plot(x1,y1,'-k');hold on;
plot(x1,0.*x1,'-k');hold on;h2=plot(x1,y2,'-k');legend([h1 h2],{'a','b'});
Then I get the following error message
Invalid argument. Type 'help legend' for more information.
I tried legend([h1 h2],['a','b']); which also does not work.
Sorry to bother you for this, thanks in advance!
  댓글 수: 5
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2023년 11월 17일
I do not know but when I used your code lines it works. I hues perhaps I forgot to use 'hold on', so maybe the error message is not about legend.
Thanks a lot!
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2023년 11월 17일
Hello Star, Thanks.
Dyuman solved the problem. I explain the problem. If you type
x1=linspace(0,2*pi,1000);y1=sin(x1);y2=cos(x1);h1=plot(x1,y1,'-k');h2=plot(x1,y2,'-k');legend([h1 h2],'a','b');
then you get the following error message:
Error using legend
Invalid argument. Type 'help legend' for more information.
The problem has nothing to do with 'legend'. The problem is that after the first plot, I forgot to add 'hold on'. But, since the error message was very irrelevant I got confused.
Thanks a lot!

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by