フィルターのクリア

how to save the content of the current figure as an image?

81 ビュー (過去 30 日間)
Nisreen Sulayman
Nisreen Sulayman 2014 年 9 月 18 日
コメント済み: Raviteja Vangara 2020 年 5 月 12 日
how to save the content(which is an image) of the current figure as an image?
I have about 30 figure ...
I want to use MATLAB commands to save them in for loop

採用された回答

Mohammad Abouali
Mohammad Abouali 2014 年 9 月 19 日
編集済み: Mohammad Abouali 2014 年 9 月 19 日
saveas(gcf,'filename.png')
would also work.
or something like this
for i=1:30
% code to show image number i
saveas(gcf,['filename' num2str(i) '.png']);
end
if you don't like the border around it type:
iptsetpref('ImshowBorder','tight');
before preparing your figure.
  3 件のコメント
Nisreen Sulayman
Nisreen Sulayman 2014 年 9 月 19 日
I want to get ride of the white
frame in the image and save only the image
Mohammad Abouali
Mohammad Abouali 2014 年 9 月 26 日
編集済み: Mohammad Abouali 2014 年 9 月 26 日
Cool image. What are these? blood stream?
Anyway, so you can use fullfile() command. Something like this should work
DirectoryPath ='C:\Mystorage\myImages';
whereToStore=fullfile(DirectoryPath,['filename' num2str(i) '.png']);
saveas(gcf, whereToStore);
If you wanna make it more fancy you can have the user select the folder through a GUI like this
DirectoryPath = uigetdir();
if DirectoryPath~=0
whereToStore=fullfile(DirectoryPath,['filename' num2str(i) '.png']);
saveas(gcf, whereToStore);
end

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

その他の回答 (3 件)

Francesco Ciriello
Francesco Ciriello 2019 年 11 月 20 日
Save current figure
imwrite(getframe(gcf).cdata, 'myfilename.png')
Save current axis
imwrite(getframe(gca).cdata, 'myfilename.png')
  1 件のコメント
Raviteja Vangara
Raviteja Vangara 2020 年 5 月 12 日
I think this deserves an upvote. I have an image with alpha data, and traditional saveas options wouldnt store alpha data in saved PNG file.
using,
H = getframe(gca)
imwrite(H.cdata, 'myfilename.png')
This saves current figure as it appears on the window.

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


Mikhail
Mikhail 2014 年 9 月 18 日
If you want to save in with your hands - just click file-> save figure.
  1 件のコメント
Nisreen Sulayman
Nisreen Sulayman 2014 年 9 月 18 日
I have about 30 figure ...
I want to use MATLAB commands to save them in for loop

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


Image Analyst
Image Analyst 2014 年 9 月 18 日
Use imwrite() if you just want to save the image you display. If you want to save the axes or figure, use export_fig(). http://matlab.wikia.com/wiki/FAQ#How_do_I_save_my_figure.2C_axes.2C_or_image.3F_I.27m_having_trouble_with_the_built_in_MATLAB_functions.
  2 件のコメント
Nisreen Sulayman
Nisreen Sulayman 2014 年 9 月 19 日
編集済み: Nisreen Sulayman 2014 年 9 月 19 日
Thank you how to save them to specific folder(path)using MATLAB command?
Image Analyst
Image Analyst 2014 年 9 月 19 日
Just use fullfile() when you construct the file name that you pass in to export_fig().

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

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by