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.

6 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Rik
Rik il 2 Gen 2020
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

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by