Save figure with a specific name

7 ビュー (過去 30 日間)
ConanTaieb
ConanTaieb 2020 年 9 月 21 日
コメント済み: ConanTaieb 2020 年 9 月 21 日
Hello,
I export data using the following code :
[file,filepath,filter] = uigetfile({'*.xlsx'},'Select your data');
filename = fullfile(filepath, file);
[data] = xlsread(filename);
I use the data to generate a figure .png and I save it using "saveas".
h=figure('Color',[1 1 1]);
...
saveas(h,'FIG','png');
How can I automatically save the figure with the same name of the selected file with uigetfile?
Thank you!

採用された回答

Walter Roberson
Walter Roberson 2020 年 9 月 21 日
[filedir, basename, ext] = fileparts(filename);
newname = fullfile(filedir, [basename '.png']);
saveas(h, newname, 'png');
  1 件のコメント
ConanTaieb
ConanTaieb 2020 年 9 月 21 日
Great !
Thanks!

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

その他の回答 (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