Plot legend for loop

I want to have a consolidated plot generated from "for loop" with legend for only first and last value of the variable.
My code would look like this
hold on
for i = 0.1:0.001:1
plot(i,cos(i))
end
hold off
My function is different than cos(i), the problem that I have is that I want to display legend for only i = 0.1 and i = 1, which I couldn't. Or is there any way I could indicate that the line belongs to i =0.1 and i=1? Any reference or help is highly appreciated.
thanks

4 comentarios

Ameer Hamza
Ameer Hamza el 21 de Mzo. de 2020
Legend belongs to a specific line, not just one point on the line. Can you show us an example of what is your required output?
Tshewang Phuntsho
Tshewang Phuntsho el 21 de Mzo. de 2020
I am looking for something like this but only to the curves associated with the extreme points. GNU plot example. I would still appreciate if anyone could help. I sort a got it but not up to this point.
madhan ravi
madhan ravi el 21 de Mzo. de 2020
Are you looking to labelling the point?
doc text % ?
Tshewang Phuntsho
Tshewang Phuntsho el 21 de Mzo. de 2020
I am looking for something like these but to only extreme curves. GNU link

Iniciar sesión para comentar.

Respuestas (1)

Peng Li
Peng Li el 21 de Mzo. de 2020

0 votos

You can try assign each line with a handle by
hold on
iHandler = 1;
for i = 0.1:0.001:1
iHandler = plot(i,cos(i));
iHanlder = iHanlder + 1;
end
hold off
After that, you can use legend([1 whateverNumCorrespondingTo1], {'your legend'}).
Or you can set DisplayName property in plot function that only has value when i = 0.1 or 1.

Productos

Versión

R2018b

Etiquetas

Preguntada:

el 21 de Mzo. de 2020

Respondida:

el 21 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by