how to create for loop in matlab?

1 vue (au cours des 30 derniers jours)
reyadh Albarakat
reyadh Albarakat le 4 Avr 2017
Modifié(e) : Jan le 5 Avr 2017
Hi All,
I have thousands of images each date has 7 bands. I need to create for-loop to calculate
MNDWI=(b4-b6)/(b4+b6)
here is example of the images
'MOD09A1.A2000057.h21v05.006.2015136062042.hdf_sur_refl_b01_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000057.h21v05.006.2015136062042.hdf_sur_refl_b02_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000057.h21v05.006.2015136062042.hdf_sur_refl_b03_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000057.h21v05.006.2015136062042.hdf_sur_refl_b04_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000057.h21v05.006.2015136062042.hdf_sur_refl_b05_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000057.h21v05.006.2015136062042.hdf_sur_refl_b06_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000057.h21v05.006.2015136062042.hdf_sur_refl_b07_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000065.h21v05.006.2015136062016.hdf_sur_refl_b01_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000065.h21v05.006.2015136062016.hdf_sur_refl_b02_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000065.h21v05.006.2015136062016.hdf_sur_refl_b03_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000065.h21v05.006.2015136062016.hdf_sur_refl_b04_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000065.h21v05.006.2015136062016.hdf_sur_refl_b05_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000065.h21v05.006.2015136062016.hdf_sur_refl_b06_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000065.h21v05.006.2015136062016.hdf_sur_refl_b07_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000073.h21v05.006.2015136060905.hdf_sur_refl_b01_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000073.h21v05.006.2015136060905.hdf_sur_refl_b02_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000073.h21v05.006.2015136060905.hdf_sur_refl_b03_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000073.h21v05.006.2015136060905.hdf_sur_refl_b04_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000073.h21v05.006.2015136060905.hdf_sur_refl_b05_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000073.h21v05.006.2015136060905.hdf_sur_refl_b06_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000073.h21v05.006.2015136060905.hdf_sur_refl_b07_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000081.h21v05.006.2015136075413.hdf_sur_refl_b01_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000081.h21v05.006.2015136075413.hdf_sur_refl_b02_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000081.h21v05.006.2015136075413.hdf_sur_refl_b03_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000081.h21v05.006.2015136075413.hdf_sur_refl_b04_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000081.h21v05.006.2015136075413.hdf_sur_refl_b05_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000081.h21v05.006.2015136075413.hdf_sur_refl_b06_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000081.h21v05.006.2015136075413.hdf_sur_refl_b07_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000089.h21v05.006.2015136062547.hdf_sur_refl_b01_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000089.h21v05.006.2015136062547.hdf_sur_refl_b02_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000089.h21v05.006.2015136062547.hdf_sur_refl_b03_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000089.h21v05.006.2015136062547.hdf_sur_refl_b04_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000089.h21v05.006.2015136062547.hdf_sur_refl_b05_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000089.h21v05.006.2015136062547.hdf_sur_refl_b06_clip.tif_mosaico_ream.tif'
'MOD09A1.A2000089.h21v05.006.2015136062547.hdf_sur_refl_b07_clip.tif_mosaico_ream.tif'
Thank you in Advance
Reyadh
  3 commentaires
reyadh Albarakat
reyadh Albarakat le 4 Avr 2017
Hi per isakson,
each date has 7 bands for example this image MOD09A1.A2000057 which I posted above, has 7 bands. if you read the entire line of each image you will find band number. Here is one of the images, Band no in BOLD (MOD09A1.A2000057.h21v05.006.2015136062042.hdf_sur_refl_ b01_clip.tif_mosaico_ream.tif)
Thank you
Reyadh
per isakson
per isakson le 4 Avr 2017
Modifié(e) : per isakson le 4 Avr 2017
I still don't understand how to find the two numbers to put into this expression
(b4-b6)/(b4+b6)

Connectez-vous pour commenter.

Réponses (1)

hamed amini
hamed amini le 4 Avr 2017
Modifié(e) : per isakson le 4 Avr 2017
look into sprintf function
>> variable_numbers1 = [1 2 3 ... 1000];
>> variable_numbers2 = [2001 2002 2003 ... 2001000];
>> for i=1:1000
>> eval(sprintf('image_bank.image%d = imread(''fixed_string%d_fixed_string%d.tiff'');',i,variable_numbers1(i),variable_numbers2(i)));
>> end
  2 commentaires
Jan
Jan le 4 Avr 2017
Modifié(e) : Jan le 5 Avr 2017
Prefer:
image_bank.image = cell(1, 1000);
for i = 1:1000
filename = sprintf('fixed_string%d_fixed_string%d.tiff', ...
i, variable_numbers1(i));
image_bank.image{i} = imread(filename);
end
hamed amini
hamed amini le 5 Avr 2017
Thanks for the link.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by