简体   繁体   English

使用nctoolbox在matlab for循环中获取文件列表

[英]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. 问题是,除非在读取每个文件之前将其激活,否则nctoolbox似乎永远无法工作(对我而言)。 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 " “警告:netcdf-java cdm不包含与该变量关联的坐标信息。返回ncvariable而不是ncgeovariable对象。(依赖于'grid'或'geosubset'等坐标信息的方法不可用。在ncgeodataset> ncgeodataset.geovariable中, 459在ncgeodataset> ncgeodataset.subsref中在622 In s4processing中在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. 我还在startup.m中添加了运行设置功能的行(我每次运行matlab时都会看到它被激活),但这也不起作用。

That warning you are getting isn't an error and has nothing to do with setup_nctoolbox . 您得到的警告不是错误,与setup_nctoolbox没有任何setup_nctoolbox You only need to run setup_nctoolbox once; 您只需要运行一次setup_nctoolbox it adjusts Matlab's path and javaclasspath to include the dependencies needed to run nctoolbox. 它将调整Matlab的路径和javaclasspath以包括运行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. 这是数据集的问题,而不是nctoolbox的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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