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

조회 수: 17 (최근 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 CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by