简体   繁体   中英

Using nctoolbox for a list of files in a matlab for-loop

I have this piece of code

sumrain=zeros(881,1121);
run('D:\nctoolbox-nctoolbox-3161fee\setup_nctoolbox.m')
for j=1:m

nc=ncgeodataset(lsf(j,:)); %lsf is a list of file names
dirvar=nc.geovariable('Total_precipitation_surface_1_Hour_Accumulation');
g=dirvar.grid_interop(1,:,:);
dir=dirvar.data(1,:,:);
dir=reshape(dir,[881 1121]);
sumrain=sumrain+dir;
 clear nc dirvar

end

The problem is, it seems like the nctoolbox never works (for me) unless it is activated before reading each file. If I put the line that runs the install file inside the loop it works fine, however the code will be very slow. But when I keep the run setup line outside the loop I get an error:

"Warning: The netcdf-java cdm contains no coordinate information associated with the variable. Returning ncvariable instead of ncgeovariable object. (Methods that rely on coordinate information like 'grid' or 'geosubset' are not available. In ncgeodataset>ncgeodataset.geovariable at 459 In ncgeodataset>ncgeodataset.subsref at 622 In s4processing at 16 "

I also put the lines to run the setup function in my startup.m (I see it being activated everytime I run matlab), but this didn't work either.

That warning you are getting isn't an error and has nothing to do with setup_nctoolbox . You only need to run setup_nctoolbox once; it adjusts Matlab's path and javaclasspath to include the dependencies needed to run nctoolbox. Running it multiple times inside a loop isn't doing anything.

That warning is just telling you that the dataset you are reading is missing coordinate variable information. That's a problem with the dataset, not nctoolbox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM