How can I automatically write (or export) many FIG-files to JPEG images in "batch mode" in MATLAB 7.8 (R2009a)?
4 views (last 30 days)
Show older comments
I have many FIG-files in a directory, and it would take a very long time to open each one individually and export them to a JPEG image. Iwould like to automate this process.
Accepted Answer
MathWorks Support Team
on 14 Sep 2009
To automate this process, run the following code at the command prompt, or in a separate script. All "*.fig" files in the current directory will be exported as JPEG images:
d=dir('*.fig'); % capture everything in the directory with FIG extension
allNames={d.name}; % extract names of all FIG-files
close all; % close any open figures
for i=1:length(allNames)
open(allNames{i}); % open the FIG-file
base=strtok(allNames{i},'.'); % chop off the extension (".fig")
print('-djpeg',base); % export to JPEG as usual
close(gcf); % close it ("gcf" returns the handle to the current figure)
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Printing and Saving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!