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

 채택된 답변

Adam Danz
Adam Danz 2019년 12월 16일

1 개 추천

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

댓글 수: 2

Adam Hermon
Adam Hermon 2019년 12월 16일
Thanks so much dude :)
Adam Danz
Adam Danz 2019년 12월 17일
Glad I could help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

질문:

2019년 12월 16일

댓글:

2019년 12월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by