Effacer les filtres
Effacer les filtres

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

6 vues (au cours des 30 derniers jours)
Chris
Chris le 8 Avr 2014
Commenté : ramez sabra le 8 Juil 2021
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

Réponse acceptée

Chandrasekhar
Chandrasekhar le 8 Avr 2014
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 commentaires
Hadj BENZATER
Hadj BENZATER le 25 Mar 2020
thanks
Lukas Guldersson
Lukas Guldersson le 3 Juin 2020
thanks

Connectez-vous pour commenter.

Plus de réponses (1)

Dishant Arora
Dishant Arora le 8 Avr 2014
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{:})

Community Treasure Hunt

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

Start Hunting!

Translated by