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

10 次查看(过去 30 天)
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..

回答(2 个)

Richard Quist
Richard Quist 2013-6-17
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

Ezgi Kurt
Ezgi Kurt 2018-7-25
Thank you!

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by