matlab - variable in plot title

后端 未结 2 1316
情书的邮戳
情书的邮戳 2021-01-12 06:51

I want to do

for i = 1 : size(N, 2)
    figure(i);
    title(\'N = %d\', i);
%other stuff

but setting the title doesn\'t work. Why?

相关标签:
2条回答
  • 2021-01-12 07:36

    num2str should also works.

    title(['N = ',num2str(i)]);
    
    0 讨论(0)
  • 2021-01-12 07:50

    Because you forgot to add sprintf

    for i = 1 : size(N, 2) 
    figure(i); 
    title(sprintf('N = %i', i)); %# %i for integer
    %other stuff
    end
    
    0 讨论(0)
提交回复
热议问题