How can a particular .tif file be read from a folder which is having 10 files with different suffix like 'file_1', 'file_2'...?I only want to read file_2.tif and file_4.tif.
조회 수: 8 (최근 30일)
이전 댓글 표시
I have used the following code
folder='D\Project';
file2=(dir(fullfile(folder,'*_2.tif)));
This code is returning a structure where the name can be read only. I want the content of the file, as it should have several rows and columns.
How can I use the geotiffread function with it to read the content of the file?
I am stuck in here. I t will be helpful if someone can assist.
댓글 수: 0
채택된 답변
Rik
2020년 1월 2일
You can generate the list of file names with dir:
filelist=dir(fullfile(folder,'*_*.tif'));
Now you can optionally loop through this struct and remove any files that don't match the pattern of files you would like to read. (if you loop backwards, you don't need to worry about skipping any of the elements)
for n=numel(filelist):-1:1
if SomeCondition
filelist(n)=[];
end
end
And now you can use the struct to feed the file names to the geotiffread function, just like the documentation describes:
A=cell(size(filelist));
R=cell(size(filelist));
for n=1:numel(filelist)
fn=fullfile(folder,filelist(n).name);
[A{n},R{n}] = geotiffread(filename);
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Acquisition Support Packages for Hardware Adaptors (Generic Video Interface)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!