tags:

views:

54

answers:

3

Hey all, I have a MATLAB program that graphs some things and then outputs the graph to a file. If I run this program several times in the same directory, the file gets overwritten each time. How can I make it so the filename it outputs to changes...

I currently have this:

print -depsc myfigure

I have strings, rate and name, that I want to use, but can't get anything to work. If I can't use my strings, something random would be fine as well. Any way to do this?

Many thanks!

+3  A: 

Name it with the current date and time:

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

run right now in PST, this creates a file called prefix_20100220T200733.eps. You can obviously change the prefix and/or the date format.

Peter
+1  A: 

You can add current time to your file name. For example:

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

This code checks if file exists, and if yes, 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);
yuk

related questions