Issues with Legend Creating and Placement

Hi, So I have a group of functions that uses an array of terms n which is listed below, I created a legend using a for loop but I was told that it is easier to do it just in one line, specifically using this one, but whenever I seem to use it, I don't get the legend and my title dissapears, if anyone could point into what im doing wrong, i'd gratly appreciate it. I also wanted to know how to make the legend be placed outside of the frame, I currently use "best" but it still seems to be there. Thanks so much in advance.
n = 0:2:10
for i = 1:6 % Original Loop
lgds{i} = sprintf('Up to n = %i',n(i));
end
% Was told can do in one line with append text to a string using a + sign. Something like this,
'n =' + n;
% Legend
legend(lgds,'FontSize',12, 'Location','best');

 Respuesta aceptada

Adam Danz
Adam Danz el 16 de Dic. de 2019
Use str = compose(formatSpec,A); requires Matlab >= r2016b
lgds = compose('Up to n = %i',n);

2 comentarios

Adam Hermon
Adam Hermon el 16 de Dic. de 2019
Thanks so much dude :)
Adam Danz
Adam Danz el 17 de Dic. de 2019
Glad I could help!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Etiquetas

Preguntada:

el 16 de Dic. de 2019

Comentada:

el 17 de Dic. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by