Add element to legend outside for loop
Mostrar comentarios más antiguos
Hi all,
I have a for loop creating 1 figure with multiple lines in it.
Outside of the for loop, I'm adding 1 more line (which can't be done within the for loop).
My legend has a value for each iteration in the for loop, but now I want to add the value of the line outside the for loop as well.
How can I do this?
test = [1 2 3 4 5 6 7 8];
test2 = [11 12 13 14 15];
for i=1:length(test)
for j=1:length(test2)
results(j,:) = [value1 value2 value3];
end
plot(results(:,1),results(:,2))
xlabel('value1')
ylabel('value2')
legend(strcat('This is my test: a = ',num2str(test')))
end
plot(results(:,1),results(:,3)) % I only need these values for the very last iteration
legend('some text no numbers or values')
3 comentarios
randerss simil
el 23 de Feb. de 2021
why is it not possible to add one more line within for loop ? Try this below
test = [1 2 3 4 5 6 7 8];
test2 = [11 12 13 14 15];
for i=1:length(test)
for j=1:length(test2)
results(j,:) = [1 2 3];
end
plot(results(:,1),results(:,2))
xlabel('value1')
ylabel('value2')
hold on;plot(results(:,1),results(:,3)) ;legend({strcat('This is my test: a = ',num2str(test')),'some text no numbers or values'})
end
Yvet
el 23 de Feb. de 2021
Yvet
el 23 de Feb. de 2021
Respuestas (1)
Jemima Pulipati
el 25 de Feb. de 2021
0 votos
Hello,
From my understanding, you want to add legend individually to the generated plot.
The following answers from the community might be of relevance to you.
Categorías
Más información sobre Legend en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
