how to define a path in saveas command

26 ビュー (過去 30 日間)
H-M
H-M 2020 年 6 月 18 日
コメント済み: H-M 2020 年 6 月 18 日
I am using saveas command in a ''for loop'' to save 20 plots in .png format. How can I add the i counter of for loop in saveas command. Many thanks
pathdatasave = 'E:\matlab';
saveas(gcf,[pathdatasave '%03d' '.png' ]);

採用された回答

Image Analyst
Image Analyst 2020 年 6 月 18 日
You probably messed up by not having the slashes correct. You should use fullfile(), like this:
folder = 'E:\matlab';
if ~isfolder(folder)
% Folder does not exist. Ask the user to browse to an existing one.
uiwait(msgbox('Please select the output folder'))
folder = uigetdir(pwd);
if folder == 0
% User clicked cancel.
return;
end
end
for k = 1 : whatever
% Some code to change the current figure...
% Now save the current figure.
baseFileName = sprintf('%03d.png', k);
fullFileName = fullfile(folder, baseFileName);
saveas(gcf, fullFileName);
end
  1 件のコメント
H-M
H-M 2020 年 6 月 18 日
Many thanks,GREAT

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

その他の回答 (1 件)

Tommy
Tommy 2020 年 6 月 18 日
Possibly like this?
pathdatasave = 'E:\matlab';
saveas(gcf,sprintf('%s%03d.png', pathdatasave, i));
  1 件のコメント
H-M
H-M 2020 年 6 月 18 日
It saves nothing

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

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by