How to save multiple MATLAB figures automatically in program?
조회 수: 132 (최근 30일)
이전 댓글 표시
In my script, I may save the figures as jpg files via the code (which works):
% print(1,'-painters,'-djpeg',strcat(filename,'r','.jpg'))
I want to do the same thing, but saving my files as figs in MATLAB. That's it, but it has to work the same, which means the filename must be saved as well. This is variable with the iterations of the program.
I should also mention there are two more print commands in the original code that are identical except for the number and the colour.
댓글 수: 0
채택된 답변
OCDER
2018년 10월 16일
편집: OCDER
2018년 10월 16일
Note: You should save using the full file name, which includes the folder path AND file name. Otherwise, you cannot use your program if your current working directory is different.
FullFileName = fullfile(FilePath, FileName)
Here's an example.
%Example
FigH = figure; %If you have other figure handles, then specify
%this when saving figures. Note: you can store
%figure handles in a cell array or gobjects
%array, in case you need to loop through the saves.
%EX: FigH{1} = figure. FigH{2} = figure.
AxH = axes;
X = 1:100;
Y = sin(X);
FileDir = pwd; %Replace with your folder
for j = 1:10
LineH = plot(AxH, X, Y*j);
FilePre = sprintf('%s-%d', 'MyFig', j);
savefig(FigH, fullfile(FileDir, [FilePre '.fig']))
print(FigH, fullfile(FileDir, [FilePre '.png']), '-r300', '-dpng')
%Changing figure color
LineH.Color = 'r';
savefig(FigH, fullfile(FileDir, [FilePre 'red.fig']))
print(FigH, fullfile(FileDir, [FilePre 'red.png']), '-r300', '-dpng')
end
댓글 수: 9
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!