フィルターのクリア

How to append a string to a filename when saving a file?

60 ビュー (過去 30 日間)
L'O.G.
L'O.G. 2022 年 3 月 30 日
コメント済み: Les Beckham 2022 年 3 月 30 日
How do I append a string to the filename and save the file in the case of saveas and save? The following isn't quite right, so I'd appreciate some insight.
[~,f,ext] = fileparts(files(id).name); % extract file name without original extension
% do some calculations and generate a plot based on the original file
str_saveas = sprintf(str_saveas,f);
saveas(fig,'str_saveas','png')
And similarly, for the save function.
  1 件のコメント
Geoff Hayes
Geoff Hayes 2022 年 3 月 30 日
@O.G. what is
str_saveas
? If you just want to append two string variables together, you could use the square brackets as
str_saveas = [str_saveas f];
sprintf would be used more like
str_saveas = sprintf('%s%s', str_saveas, f);

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

採用された回答

Les Beckham
Les Beckham 2022 年 3 月 30 日
This should get you closer to what you want to do
[~,f,ext] = fileparts(files(id).name); % extract file name without original extension
% do some calculations and generate a plot based on the original file
str_append = 'text_that_you_want_to_add';
str_saveas = sprintf('%s_%s', f, str_append); % add the appended string to the original filename
saveas(fig, str_saveas, 'png') % note no quotes on the filename since it is a variable
  2 件のコメント
L'O.G.
L'O.G. 2022 年 3 月 30 日
Thanks!
Les Beckham
Les Beckham 2022 年 3 月 30 日
You are welcome.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by