MATLAB: How to automatically write (or export) many FIG-files to JPEG images in “batch mode” in MATLAB 7.8 (R2009a)

.jpgautomatic;batchexportjpegMATLABprint

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.

Best Answer

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
Related Question