adding legend that is comes from a variable
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Benjamin
el 6 de Mzo. de 2019
Comentada: Stephen23
el 13 de Mayo de 2021
I have a variable that looks like this:
eta = [0.4843 0.3927];
Note that I access both of these later in a loop.
How can I create a legend after my plot command to automatically make the first one the first eta entry (0.4843) and the second line in the plot to be the second eta entry (0.3928)? How can I do this dynamically so that it is automated if I change the values in eta or if I make it have more numbers?
2 comentarios
Respuesta aceptada
dpb
el 6 de Mzo. de 2019
LEGEND() requires text, not numeric data for the legend text...
hL=legend(num2str(eta(:),'%.4f')); % salt format string to taste...
NB: must orient eta as column vector to not run the strings together horizontally all into one...
3 comentarios
Stephen23
el 13 de Mayo de 2021
Since R2016b using the string class is simpler:
eta = [0.4843,0.3927];
legend(string(eta))
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!