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');

 Akzeptierte Antwort

Adam Danz
Adam Danz am 16 Dez. 2019

1 Stimme

Use str = compose(formatSpec,A); requires Matlab >= r2016b
lgds = compose('Up to n = %i',n);

2 Kommentare

Adam Hermon
Adam Hermon am 16 Dez. 2019
Thanks so much dude :)
Adam Danz
Adam Danz am 17 Dez. 2019
Glad I could help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by