PNG vs. FIG File format - saveas function query

Hi,
I've been using the saveas function in my code to save the .fig files. However, the format of the .PNG file is quite different. The PNG file looks (size/ font) is different to the .fig plot.
But when I manually saveas from the matlab figure, File-->Save As (save as a PNG file), it saves it correctly without any change in the figure properties.
Is it something that we can make it similar to the .fig file?
Appreciate any responses, thanks in advance!
-Ferdinand

1 件のコメント

Rik
Rik 2018 年 4 月 20 日
Do you mean you want to save the figure contents to a png, just as when you would make a screen capture? If so, there is a submission on the FEX that does just that and is compatible with just about every conceivable Matlab release.

サインインしてコメントする。

 採用された回答

Jan
Jan 2018 年 4 月 21 日

0 投票

 the format of the .PNG file is quite different

It depends on what you save in the PNG, or in other word, if you save a screenshot or use print to create a PNG with modified properties.

To get a copy of the appearance of the figure:

F = getframe(FigHandle);
if isempty(F.colormap)
  RGB = F.cdata;
else
  RGB = ind2rgb(F.cdata, F.colormap);
end
imwrite(RGB, FileName, 'png');

4 件のコメント

Ferd
Ferd 2018 年 4 月 23 日
編集済み: Stephen23 2018 年 4 月 23 日

Great! This is exactly what I required. Thanks!

Will use the above method instead of what I was using, below was what I used,

saveas(gcf,[Savepath 'Plots - ' eval('filenames{i}') '.png']);
Stephen23
Stephen23 2018 年 4 月 23 日

@Ferd: why do you need to use eval? It seems to serve no purpose:

saveas(gcf,[Savepath,'Plots - ',filenames{i},'.png'])

or even more robustly using fullfile:

fnm = fullfile(Savepath,['Plots - ',filenames{i},'.png'])
saveas(gcf,fnm)
Jan
Jan 2018 年 4 月 24 日

@Ferd: Avoid eval as hell. See Tutorial: Avoid EVAL.

Ferd
Ferd 2018 年 4 月 24 日
Didn't have info on it, was trying to write my own code. Updated it with the changes. eval will be avoided at all cost. Feel Mathworks should take away the function for upcoming versions.
Appreciate the advice/ suggestions outside the question, thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePrinting and Saving についてさらに検索

タグ

質問済み:

2018 年 4 月 20 日

コメント済み:

2018 年 4 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by