简体   繁体   English

Matlab无法处理数据

[英]Matlab can't handle data

I've been working on the processing 2 lists of 855 4000x4000 matrices.我一直在处理 2 个 855 4000x4000 矩阵列表。 Here is a list of 855 matrices of some value, another one is a list of coordinates (another 855 4000x4000 matrices).这是一些值的 855 个矩阵的列表,另一个是坐标列表(另一个 855 4000x4000 矩阵)。 It's important to do it within the one cycle, in order to not to have thousands of useless variables.在一个周期内完成它很重要,以免有成千上万个无用的变量。 For every file, it cuts (read put NaN where I don't need data) coordinates data, then it cuts data related to the coordinates.对于每个文件,它都会剪切(读取将 NaN 放在我不需要数据的地方)坐标数据,然后剪切与坐标相关的数据。 Then it gathers all the values into one matrix.然后它将所有值收集到一个矩阵中。 The code is:代码是:

for x = 1:length(list_with_par)
    cd 'D:\Coord'
    par_lon = ncread(list_with_coordinates(x,:), 'longitude');
    par_lon(par_lon>=15) = nan;
    par_lon(par_lon<=-18) = nan;
    
    par_lat = ncread(list_with_coordinates(x,:), 'latitude');
    par_lat(par_lon>=84) = nan;
    par_lat(par_lon<=76) = nan;
    
    cd 'D:\Par'
    par = ncread(list_with_par(x,:), 'PAR');
    
    for i = 1:size(ncread(list_with_par(x,:),'PAR'),1) %size(,1)
        for z = 1:size(ncread(list_with_par(x,:),'PAR'),2) %size(,2)
            if isnan(par_lon(i,z))
                par(i,z) = nan;
            end
            if isnan(par_lat(i,z))
                par(i,z) = nan;
            end
        end
    end
    if size(par,2) < size(PAR_main,2)
        left_cells = size(PAR_main,2) - size(par,2);
        temp_cell = NaN(4865,left_cells);
        C2 = cat(2,par,temp_cell);
    end
    if size(par,2) == size(PAR_main,2)
        C2 = par(:,:,1);
    end
    PAR_main(:,:,x) = C2(:,:,1);
end

But suddenly an error pops up after 4-5 hours of processing.但是在处理4-5小时后突然出现错误。

Error using netcdflib
The NetCDF library encountered an error during execution of 'open' function - 'HDF error (NC_EHDFERR)'.

Error in netcdf.open (line 67)
        [varargout{:}] = netcdflib ( 'open', filename, varargin{1} );

Error in internal.matlab.imagesci.nc/openToRead (line 1278)
            this.ncRootid = netcdf.open(this.Filename,'NOWRITE');

Error in internal.matlab.imagesci.nc (line 121)
                    this.openToRead();

Error in ncread (line 61)
ncObj   = internal.matlab.imagesci.nc(ncFile);

What might be an issue?可能是什么问题?

I'm not really familiar with ncread (and associated functions), but there two things that jump out at me that appear to be very inefficient:我对 ncread(和相关函数)不是很熟悉,但有两件事让我印象深刻,它们似乎效率很低:

  1. In your loops over 'i' and 'z', is there a reason to read in the data again to determine its size instead of just using the 'par' variable that you already saved?在“i”和“z”的循环中,是否有理由再次读入数据以确定其大小,而不是仅仅使用您已经保存的“par”变量?

    for i = 1:size(par,1)对于 i = 1:size(par,1)

    for z = 1:size(par,2)对于 z = 1:size(par,2)

  2. For that matter, unless I am missing something specific to this set of functions, you should be able to skip the loops over 'i' and 'z' completely and vectorize the calculation:就此而言,除非我遗漏了这组函数的特定内容,否则您应该能够完全跳过 'i' 和 'z' 的循环并向量化计算:

    par(isnan(par_lon))= nan;标准杆(isnan(par_lon))=南;

    par(isnan(par_lat)) = nan; par(isnan(par_lat)) = nan;

This is certainly significantly slowing down your code.这肯定会显着降低您的代码速度。 It is hard to say beyond that, but I could definitely see how having millions of extraneous file reads could cause some issues with either temporary file addresses, etc.) or memory leaks.很难说除此之外,但我可以肯定地看到有数百万次无关的文件读取会如何导致临时文件地址等问题)或 memory 泄漏。

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

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