Open Modis images in a loop and apply NDVI on them
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello,
I have a 12 modis images that I want to open in a loop. and I just don't know how, I want only to work on their first and second bands ( as it is mentioned in the picture )
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/192662/image.jpeg)
Also I tried to apply NDVI and I dont know why It doesn't work ( picture 2)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/192664/image.jpeg)
댓글 수: 0
답변 (1개)
Kevin Chng
2018년 10월 27일
편집: Kevin Chng
2018년 10월 27일
Hi
first of all, load your information into array first, which allow you to use indexing to get their information later.
folder='E:\Matlab';
filetype='*.hdf';
f=fullfile(folder,filetype);
d=dir(f);
for i=1:numel(d);
Red(i) = hdfread(fullfile(folder,d(i).name), 'MORIS_Grid_500m_2D','Fields','sur_ref1_b01_1');
NIR(i) = hdfread(fullfile(folder,d(i).name), 'MORIS_Grid_500m_2D','Fields','sur_ref1_b02_1');
end
After the code above, now we use indexing to get the information from the array for our calculation.
for i=1:1:numel(d)
NDVI(i) = double(NIR(i)-Red(i)) ./ (double (NIR(i) + Red(i)));
end
Kindly accept my answe if they are working for you.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!