Saving images inside a loop with changing filename

2 ビュー (過去 30 日間)
Levente Gellért
Levente Gellért 2023 年 1 月 13 日
コメント済み: Levente Gellért 2023 年 1 月 14 日
Dear Community, in a similar situation I would like to save images inside a loop. I do not know why there is an invalid character error in the filename. The filename should look like: actual foldername, Roi and a number.
Please share your suggestions:
Best:
lg
I=rand(20,20);
[~,fo{1,1},~]=fileparts(pwd);
for i=1:10
index=i
imwrite(I,'[ fo{1,1} '_' 'Roi' '_' num2str(index)].tiff')
end

採用された回答

Matt J
Matt J 2023 年 1 月 14 日
編集済み: Matt J 2023 年 1 月 14 日
I=rand(20,20);
[~,fo{1,1},~]=fileparts(pwd);
for i=1:10
index=i
imwrite(I, fo{1,1} + "_Roi_" + index + ".tiff" )
end

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 1 月 14 日
編集済み: Walter Roberson 2023 年 1 月 14 日
imwrite(I,'[ fo{1,1} '_' 'Roi' '_' num2str(index)].tiff')
Invalid text character. Check for unsupported symbol, invisible character, or pasting of non-ASCII characters.
You start a character vector. The first character of the vector is the '[' character. The second character is space. The third character is 'f' then 'o' then '{' then '1', ',', '1', '}' then space. You then end the character vector. After that you have an underscore immediately after the end of the character vector . But the underscore is not part of a variable name and is not a valid variable name by itself, and underscore is not a valid operator name. The underscore is invalid there.
I suggest you use
filename = fo{1,1} + "_Roi_" + index + ".tiff"
imwrite(I, filename)
  1 件のコメント
Levente Gellért
Levente Gellért 2023 年 1 月 14 日
Dear Walter Robertson, thanks for the detailed explanation! Best lg

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

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by