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!