Problem while reading multiple images from a file

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

Thanks for your answer @David Hill but i get an error when i try to use it :
Error using imread>parse_inputs (line 501)
The file name or URL argument must be a character vector or string scalar.
Error in imread (line 339)
[source, fmt_s, extraArgs, was_cached_fmt_used] = parse_inputs(cached_fmt, varargin{:});
Sorry, should be sprintf
Thankss!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

질문:

2022년 7월 26일

댓글:

2022년 7월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by