How can I load multiple tiff files through a loop?
이전 댓글 표시
I am trying to load multiple tiff files like this:
for i=66:96
LSTday=strcat('Research\MODIS\MOD11A1\MOD11A1.006_LST_Day_1km_doy20101',string(i));
end
but, I keep getting imread error: Error using imread>parse_inputs (line 450)
The file name or URL argument must be a character vector.
Can anyone kindly help me what is the issue?
댓글 수: 2
Walter Roberson
2022년 3월 13일
Which MATLAB release are you using? There were a small number of releases after string() was introduced but before imread() recognized it.
Mery960
2022년 3월 13일
채택된 답변
추가 답변 (2개)
Walter Roberson
2022년 3월 13일
0 개 추천
In R2018a, imread() requires a character vector, not a string() object.
The first release that supported string objects for file names was R2018b, the release after you have.
댓글 수: 3
Mery960
2022년 3월 13일
"Is there any other function I can use to read the string file in a loop then?"
Use a character vector rather than a string, just as Walter Roberson wrote.
"I have way too many data to load."
The MATLAB documentation show how to load multiple files. Note that it recommends SPRINTF:
Walter Roberson
2022년 3월 13일
char() of a string scalar gives you a character vector
Voss
2022년 3월 14일
In place of the code you posted, do this:
file_name_prefix = 'Research\MODIS\MOD11A1\MOD11A1.006_LST_Day_1km_doy20101';
for i = 66:96
LSTday = sprintf('%s%d',file_name_prefix,i);
end
And use LSTday the same as you are already doing in the rest of the code, e.g., using it in imread().
댓글 수: 2
Image Analyst
2022년 3월 15일
Except that I think you really meant to use fullfile() which is more robust since it doesn't care if the folder ends with a slash or not - it will always get it right.
Voss
2022년 3월 15일
Well, I didn't want to assume that 'MOD11A1.006_LST_Day_1km_doy20101' is a directory when it might be part of the file names, e.g., file names might be:
- MOD11A1.006_LST_Day_1km_doy2010166
- MOD11A1.006_LST_Day_1km_doy2010167
- etc.
OP has reported: "Researcj\MODIS\MOD11A1\MOD11A1.006_LST_Day_1km_doy20101\96.tiff does not exist." but that could be for any one of a number of reasons.
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!