Saving the output figures using saveas() as full sized images

56 ビュー (過去 30 日間)
Mathan
Mathan 2022 年 5 月 11 日
コメント済み: Mathan 2022 年 6 月 7 日
Hi all,
I was trying to save the output plots directly into my present directory using the saveas() command. Even though it saves successfully I am having some trouble in saving them as full screen sized images. I used the following code:
a=[1:1:10];
figure1 = figure(1);
plot(a,sin(a));
figure1.WindowState = 'maximized';
saveas(figure1,'fig1.png')
b = [100:1:110];
figure2 = figure(2);
plot(b,cos(b));
figure2.WindowState = 'maximized';
saveas(figure2,'fig2.png')
c = [0.1:0.01:1];
figure3 = figure(3);
plot(c,sin(c));
figure3.WindowState = 'maximized';
saveas(figure3,'fig3.png')
d = [1000:10:1100];
figure4 = figure(4);
plot(d,cos(d));
figure4.WindowState = 'maximized';
saveas(figure4,'fig4.png')
When I run this, some of the plots are saved as required (i.e. after maximizing and then saving - attached as fig1, fig2, fig3.png) whereas some are saved without maximizing (attached as fig4.png). I also tried 'fullscreen' instead of maximizing, but the results stay the same.
It would be great if someone could point me in the right direction.
Thanks

採用された回答

M.B
M.B 2022 年 5 月 12 日
編集済み: M.B 2022 年 5 月 12 日
Try the export_fig function in File exchange. The function will give you control over the size of the figure.
  3 件のコメント
M.B
M.B 2022 年 6 月 7 日
Yes. You can include the path in the file name (The first input argument of the function).
fig = figure(123); plot([0 1], [0 1]);
export_fig('C:\mynewimage.jpg', '-jpg', fig, '-m2');% will save the image in C:/
Mathan
Mathan 2022 年 6 月 7 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

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