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

조회 수: 1 (최근 30일)
Keith Grey
Keith Grey 2020년 5월 19일
댓글: Benjamin Großmann 2020년 5월 19일
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
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").
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
Keith Grey
Keith Grey 2020년 5월 19일
편집: Keith Grey 2020년 5월 19일
saveas(gcf,sprintf('%s - Title).png', NAME))
I worked it out! Thank you!
Benjamin Großmann
Benjamin Großmann 2020년 5월 19일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by