Is it possible to insert in a legend a calculated variable?

조회 수: 2 (최근 30일)
Chris
Chris 2014년 4월 8일
댓글: ramez sabra 2021년 7월 8일
Hey everybody,
ts me again with an maybe simple question for you. I have a for loop and calculate some data, which I plot at the end of each loop. Is it possible to define, that the legend will have an calculated data in it? Such as loop one z=1, loop two z=2.5 and so on.
Thanks in advance for some help

채택된 답변

Chandrasekhar
Chandrasekhar 2014년 4월 8일
for eg:
z = 1;
%loop1
data1 = [1:10];% data obtained in loop1
z = 2.5;
%loop2
data2 = [1:2.5:25];% data obtained in loop2
plot(data1);
hold
plot(data2,'r');
legend('z = 1','z = 2.5');
xlabel('xaxis');
ylabel('yaxis');
grid on
  댓글 수: 6

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

추가 답변 (1개)

Dishant Arora
Dishant Arora 2014년 4월 8일
str = {strcat('z = ' , num2str(z))} % at the end of first loop, z being loop output
str = [str , strcat('z = ' , num2str(z))] % after 2nd loop
% plot your data
legend(str{:})

카테고리

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