how to create for loop in matlab?

1 次查看(过去 30 天)
reyadh Albarakat
reyadh Albarakat 2017-4-4
编辑: Jan 2017-4-5
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 个评论
reyadh Albarakat
reyadh Albarakat 2017-4-4
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 2017-4-4
编辑:per isakson 2017-4-4
I still don't understand how to find the two numbers to put into this expression
(b4-b6)/(b4+b6)

请先登录,再进行评论。

回答(1 个)

hamed amini
hamed amini 2017-4-4
编辑:per isakson 2017-4-4
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 个评论
Jan
Jan 2017-4-4
编辑:Jan 2017-4-5
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by