hdf for loop

조회 수: 7 (최근 30일)
sergio
sergio 2012년 5월 31일
Hello! I'm trying to loop over a series of hdf files inside a folder. I get the map for the first iteration but fail to continue. Can somebody let me know what is the error that is causing the loop to stop in the second iteration? Thank you
clear all
close all
clc
cd('E:\MOD05_Jan2008')
files = dir('*.hdf');
for k = 1:numel(files)
lat=double(hdfread(files(k).name, '/mod05/Geolocation Fields/Latitude', 'Index', {[1 1],[1 1],[406 270]}));
lon=double(hdfread(files(k).name, '/mod05/Geolocation Fields/Longitude', 'Index', {[1 1],[1 1],[406 270]}));
WV=double(hdfread(files(k).name, '/mod05/Data Fields/Water_Vapor_Infrared', 'Index', {[1 1],[1 1],[406 270]}))*0.001;
latlim = [min(min(lat)) max(max(lat))];
lonlim = [min(min(lon)) max(max(lon))];
fir = find(WV<0);
WV(fir) = NaN;
cd('C:\Users\Guest\Desktop')
figure(1)
axesm('mercator','MapLatLimit',latlim,'MapLonLimit',lonlim,'MeridianLabel','on', ... 'ParallelLabel','on');
surfm(lat,lon,WV)
colorbar
title('Total Precipitable Water Distribution Over Southwest Africa (cm)')
xlabel('Longitude')
ylabel('Latitude')
end
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2012년 5월 31일
-Are you sure you don't just get the map from the last one?
-If there is an error, what is it?

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

답변 (1개)

Oleg Komarov
Oleg Komarov 2012년 5월 31일
You are switching to another directory
cd('C:\Users\Guest\Desktop')
it means that it cannot find the files with name files(k).name in 'C:\Users\Guest\Desktop'
Use:
hdfread(fullfile('path to hdf files', files(k).name),...)
  댓글 수: 2
sergio
sergio 2012년 5월 31일
Thaks Oleg! I made the correction but now get this error:
Undefined function 'eq' for input arguments of type 'cell'.
Error in fullfile (line 39)
elseif (f(end)==fs) || (part(1)==fs || (bIsPC && (f(end)=='/' || part(1)=='/')) )
Error in modis2 (line 10)
lat=double(hdfread(fullfile('E:\MOD05_Jan2008', files(k).name, '/mod05/Geolocation Fields/Latitude', 'Index', {[1
1],[1 1],[406 270]})));
Thanks for your help
Oleg Komarov
Oleg Komarov 2012년 5월 31일
You forgot to close the )

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

카테고리

Help CenterFile Exchange에서 HDF5에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by