MATLAB - print schedule with different product names

I have a MATLAB program that displays some things and then prints a graph to a file. If I run this program several times in the same directory, the file is overwritten each time. How can I make the name of the file that it issues change ...

I currently have this:

print -depsc myfigure

I have strings, speed and name that I want to use, but cannot make anything work. If I can not use my lines, then random will be fine. Any way to do this?

Many thanks!

+3
source share
4 answers

Call it the current date and time:

print('-depsc2', ['prefix_' datestr(now, 30)])

PST, prefix_20100220T200733.eps. , / .

+4

. :

m=magic(10);
fh=figure, surf(m);
currenttime= datestr(now,'MMSSFFF');
print(['-f',num2str(fh)],'-depsc',['outputFileName_',currenttime,'.eps']);
+2

This code checks if the file exists, and if so, adds a counter to its name.

filename = 'myfigure';
if exist([filename '.eps'],'file')
    k=1;
    while exist([filename '_' num2str(k) '.eps'], 'file')
        k=k+1;
    end
    filename = [filename '_' num2str(k)]);
end
print('-depsc', filename);
+2
source

Simple worked for me.

currenttime= datestr(now,'dd-mm-yy_HH:MM')
filename= ['graph' currenttime '.jpg']
print('-dpdf',filename)

Or any other file format you want to export. Check print help. A.

0
source

Source: https://habr.com/ru/post/1733727/


All Articles