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

18 ビュー (過去 30 日間)
amrinder
amrinder 2013 年 6 月 8 日
回答済み: Ezgi Kurt 2018 年 7 月 25 日
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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by