I have a list of .fig
files in a directory.
How do I write a simple matlab function that converts all the .fig
files to .jpg
files automatically?
I have a list of .fig
files in a directory.
How do I write a simple matlab function that converts all the .fig
files to .jpg
files automatically?
Matlab figs are just matrices which you have to load into Matlab to interpret and convert, so you can try something like this:
fig=openfig(FileName,'new','invisible');
saveas(fig,OutputFileName.jpg,'jpg')
close(fig);
The 'invisible' option does not open the fig in a plot, so it saves memory and time.
GameOfThrows' answer was useful in saving a single .fig
file to .jpg
To loop through all the .fig
files, this worked for me:
//obtain the files with .fig extension
files = dir('*.fig');
//loop through the .fig files
for i=1:length(files)
//obtain the filename of the .fig file
filename = files(i).name;
//open the figure without plotting it
fig = openfig(filename, 'new', 'invisible');
//save the figure as a jpg
saveas(fig, 'example.jpg');
//close the figure so that the next could be opened without some java problem
close;
end