Save a .FIG as .JPG (syntax error?)

1 Ansicht (letzte 30 Tage)
Keith Grey
Keith Grey am 19 Mai 2020
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?

Akzeptierte Antwort

Benjamin Großmann
Benjamin Großmann am 19 Mai 2020
Bearbeitet: Benjamin Großmann am 19 Mai 2020
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").
e.g.:
clearvars, close all
clc
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.
  3 Kommentare
Keith Grey
Keith Grey am 19 Mai 2020
Bearbeitet: Keith Grey am 19 Mai 2020
saveas(gcf,sprintf('%s - Title).png', NAME))
I worked it out! Thank you!
Benjamin Großmann
Benjamin Großmann am 19 Mai 2020
You are welcome. Please consider to substitue gcf by a figure handle returned from the figure() command. gcf can become very confusing when dealing multiple figures or if you have user interaction.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by