how to create for loop in matlab?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
per isakson
il 4 Apr 2017
Modificato: per isakson
il 4 Apr 2017
I still don't understand how to find the two numbers to put into this expression
(b4-b6)/(b4+b6)
Risposte (1)
hamed amini
il 4 Apr 2017
Modificato: per isakson
il 4 Apr 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 Commenti
Jan
il 4 Apr 2017
Modificato: Jan
il 5 Apr 2017
Do not create variables dynamically using eval. See https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
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
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!