Problem by saveas plot

10 ビュー (過去 30 日間)
CSCh
CSCh 2020 年 12 月 20 日
回答済み: Image Analyst 2021 年 1 月 5 日
Hi everyone, I do not understand what I'am doing woring in saving my plot.
My code:
Temp=[num2str(vaiable), 'Myplotnumber' ,num2str(n) ,'-dpng'];
saveas(gcf,Temp);
it save the figure always with Var1Myplotnumber2.png.fig
why put matlab .fig at the end?
Thank you?
  3 件のコメント
CSCh
CSCh 2020 年 12 月 20 日
If I use print(gca, Temp)
I got:
Error using alternatePrintPath
Invalid or unsupported printer '' specified.
Error in print (line 83)
pj = alternatePrintPath(pj);
Ive J
Ive J 2020 年 12 月 20 日
Pass gcf and not axes
print(gcf, 'test', '-dpng', '-r400')

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

採用された回答

CSCh
CSCh 2021 年 1 月 4 日
Thank you all so much for your help. In my case the '-dpng' ending did not work.
if I change to:
Temp=['%MyName%' ,'.png'];
saveas(gcf, Temp)
it saves png format.
BR

その他の回答 (3 件)

Image Analyst
Image Analyst 2020 年 12 月 20 日
Use exportgraphics() instead if you have R2020a or later.
  7 件のコメント
CSCh
CSCh 2020 年 12 月 21 日
Yes that works for me, but why does not my code work? Maybe something with my loop (num2str (n)), I have to check..
Image Analyst
Image Analyst 2020 年 12 月 21 日
I don't know. You never showed me your exportgraphics() code that didn't work. You only showed it where it worked in the command window with a hard-coded filename string. Please post the non-working code from your m-file. Apparently it thinks your Temp did not have an extension on it. Are you sure Temp ends in '.png'?

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


Walter Roberson
Walter Roberson 2020 年 12 月 21 日
Temp = {sprintf('%dMyplotnumber%d.png', vaiable, n),'-dpng'};
saveas(gcf, Temp{:})

Image Analyst
Image Analyst 2021 年 1 月 5 日
You can do
baseFileName = sprintf('%d Myplotnumber %d.png', variable, n); % Name without folder.
fullFileName = fullfile(yourFolder, baseFileName); % Prepend folder.
saveas(gcf, fullFileName);

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by