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
hamed amini
hamed amini 2017년 4월 5일
Thanks for the link.

댓글을 달려면 로그인하십시오.

카테고리

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