matlab - variable in plot title

31,825

Solution 1

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

Solution 2

num2str should also works.

title(['N = ',num2str(i)]);
Share:
31,825

Related videos on Youtube

Yebac
Author by

Yebac

Updated on July 09, 2022

Comments

  • Yebac
    Yebac almost 2 years

    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?

Related