Stephou Dcqr
Stephou Dcqr

Reputation: 23

Change figure name in every loop Matlab

I'm a beginner in Matlab but I must use it for my master thesis...

I must change the name of my figure and the name of the file I'll save for every loop I've tried that using the function "eval" as in the figure name is supposed to be written, as "Figure - Date which will change at each loops" but the way I used it is wrong. What could another function do this work? Or how do I have to change the setting of eval?

NAME={'Sept-Oct 2015','Nov 2015','Jan-Fe 2016','Fev 2016','Mars-Av 2016','Av-Mai 2016','Juin 2016','Juil 2016','Août 2016','Sept 2016','Oct 2016','Nov 2016','Déc 2016'};

for k=1:13
plot(time,data,'g');
eval(title('Figure -' NAME{1,k},'fontsize';14))
axis tight
eval(saveas(gcf,'Figure -' NAME{1,k},'eps'))
end

Thank you very much for the help.

Upvotes: 1

Views: 630

Answers (1)

EBH
EBH

Reputation: 10440

Here is a fixed version of your code, with minimal change, if I got your intention correctly.

NAME={'Sept-Oct 2015','Nov 2015','Jan-Fe 2016','Fev 2016','Mars-Av 2016','Av-Mai 2016','Juin 2016','Juil 2016','Août 2016','Sept 2016','Oct 2016','Nov 2016','Déc 2016'};

for k = 1:13
    plot(time,data,'g');
    title(['Figure -' NAME{1,k}],'fontsize',14)
    axis tight
    saveas(gcf,['Figure -' NAME{1,k}],'eps')
end

However, right now you plot 13 times the same figure (with a different title), so I guess data and time should be indexed somehow. Also keep in mind that this changes the title of the figure (which is printed in it), not it's name (which appears at the top of the window/tab).

Upvotes: 1

Related Questions