Problem while reading multiple images from a file

2 ビュー (過去 30 日間)
lena kappa
lena kappa 2022 年 7 月 26 日
コメント済み: lena kappa 2022 年 7 月 26 日
Hello everyone!
I am trying to read some images from a file and have written this code:
outLoopValues = [1.5, 2.0, 2.5] % Whatever values you want.
for m = 1 : length(outLoopValues)
index = outLoopValues(m);
I = imread('Im - %.1fcm.png', m);
f1=figure;
imshow(I)
targetSize = [960 960];
r = centerCropWindow2d(size(I),targetSize);
J = imcrop(I,r);
end
but i get this error:
Error using imread>get_full_filename (line 567)
File "Im - %.1fcm.png" does not exist.
The problem seems to be that the values that are paased to m in the for loop are not 1.5 etc but 1.500 so when it tries to find my image which is named Im - 1.5cm it cant because m is 1.500 and not 1.5
Do you know how to fix this?

採用された回答

David Hill
David Hill 2022 年 7 月 26 日
編集済み: David Hill 2022 年 7 月 26 日
I = imread(sprintf('Im - %.1fcm.png', m));
  3 件のコメント
David Hill
David Hill 2022 年 7 月 26 日
Sorry, should be sprintf
lena kappa
lena kappa 2022 年 7 月 26 日
Thankss!!!

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

その他の回答 (0 件)

カテゴリ

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