フィルターのクリア

How to save a Figure to a PNG File

399 ビュー (過去 30 日間)
Michael Angeles
Michael Angeles 2023 年 2 月 5 日
編集済み: Sulaymon Eshkabilov 2023 年 2 月 5 日
My code below seems to generate and save the "figure" file. However, when I want to save this to a *.png file I tend to get an error.
How can I save a *.fig file and also generate and save a *.png file? I think I am doing something wrong with the code.
Any help is appreciated.
plot1 = plot(freq,magB_0_AOR00,freq,magB_0_AOR45,freq,magB_0_AOR90,...
freq,magC_0_AOR00,freq,magC_0_AOR45,freq,magC_0_AOR90);
title('Data Investigation');
subtitle('A=PT0, B=PT1, C=PT2')
legend('B0^{\circ}','B45^{\circ}','B90^{\circ}',...
'C0^{\circ}','C45^{\circ}','C90^{\circ}','Location','southwest');
ylabel('Magnitude');
xlabel('Frequency (GHz)');
saveas(gcf,'CompileData.fig');

採用された回答

the cyclist
the cyclist 2023 年 2 月 5 日
According to the documentation for saveas, you should be able to do
saveas(gcf,'CompileData.png')
If that doesn't work, then you could upload your data here, for us to test.

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 2 月 5 日
編集済み: Sulaymon Eshkabilov 2023 年 2 月 5 日
Here are two different ways how you can save the plot figure output in .png:
F = @(t)exp(sin(2*t));
fplot(F, [-pi, pi])
grid on
% using saveas
OUT_File_Name = 'MY_plot';
saveas(gcf, OUT_File_Name, 'png')
% using exportgraphics()
OUT_File_Name2 = 'MY_plot2.png';
exportgraphics(gca, OUT_File_Name2)

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by