how to print multiple figures on screen using -depsc command??

90 views (last 30 days)
amrinder
amrinder on 8 Jun 2013
Answered: Ezgi Kurt on 25 Jul 2018
hello all, i got this problem in which i have executed a script and got 6 figures on my screen. now i want to create .eps file of each of them using print command. how can i create eps files of each using such a command such that all 6 files get saved separately in the working folder with the desired name given by me.
i used this script
fnames = {'file1', 'file2', 'file3, file4', 'file5', 'file6'};%
for k=1:length(fnames)%
print('-depsc',fnames{k}) % fnames is a cell of string arrays so,
% each element is a string
end%
but it saved a single file 6 times
plz help me in this... thanx..

Answers (2)

Richard Quist
Richard Quist on 17 Jun 2013
Since you didn't specify it in the print command, MATLAB will print the current figure each time. In your case, since you have 6 figures, you need to tell MATLAB which one you want to print.
You could maintain a list of the 6 figures you create and then use that list in the call to print:
figs(1) = figure; % create first figure
plot...% plot your data
figs(2) = figure;
...
% create the rest of your figures, storing each into figs
...
Or, if you always want to print all of the figures that you have created, you can ask MATLAB to give you the list:
figs = findobj(0, 'type', 'figure');
Then, print the figures. In the loop below I'm using sprintf() to "build" the output filename by * starting with a common basename: 'file', * adding the loop index, * and appending '.eps' to the end, so we get file1.eps, file2.eps etc:
for k=1:length(figs)
% print each figure in figs to a separate .eps file
print(figs(k), '-depsc', sprintf('file%d.eps', k))
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!