Save a .FIG as .JPG (syntax error?)
3 次查看（过去 30 天）
I currently have a string varible that updates my fig title and file names.
savefig(sprintf('%s - F vs V.fig', NAME))
But I also want to save a .JPG of the file too. I've tried:
saveas(sprintf('%s - F vs V', NAME),'.jpg')
Is there a syntax error I'm overlooking?
Benjamin Großmann 2020-5-19
编辑：Benjamin Großmann 2020-5-19
To save a jpg with saveas() you have to give a proper figure handle (at least gcf) as first argument and change '.jpg' to 'jpeg' as format specifier (no dot and including the "e").
clearvars, close all
NAME = 'myFig'; % figure name and prefix of jpeg file name
fig = figure('Name', NAME); % creates figure and returns figure handle
plot(rand(100,1)) % plot some random data
saveas(fig, sprintf('%s - F vs V', NAME),'jpeg') % save as jpeg
However, i would recommend to use a vector graphics format or png instead of jpeg, because jpeg could contain ugly artifacts.