Matlab写入nc文件遇到‘Start+count exceeds dimension bound (NC_EEDGE)‘问题的解决办法

最近在使用matlab写入nc文件,具体的处理视频可参见B站视频(1.matlab处理nc文件--文件读取和写入_哔哩哔哩_bilibili)但是遇到了以下的问题:

Error using netcdflib
The NetCDF library encountered an error during execution of 'putVaraDouble' function - 'Start+count exceeds dimension bound (NC_EEDGE)'.

Error in netcdf.putVar (line 84)
netcdflib(funcstr,ncid,varid,varargin{:});

Error in internal.matlab.imagesci.nc/write (line 844)
                netcdf.putVar(gid, varid,start, count, varData);

Error in ncwrite (line 75)
ncObj.write(varName, varData, start, stride);

Error in Untitled (line 31)
ncwrite('Hydrological_Tibet_G300_trend_vgwstime.nc','z',O.rg);

写入nc文件的matlab代码为:

nccreate('Hydrological_Tibet_G300_trend_vgwstime.nc','z','Dimensions',{'lon',360,'lat',180},...
    'format','netcdf4','fillvalue','disable','deflatelevel',2);
nccreate('Hydrological_Tibet_G300_trend_vgwstime.nc','lat','dimensions',{'lat',180});
nccreate('Hydrological_Tibet_G300_trend_vgwstime.nc','lon','dimensions',{'lon',360});
ncwrite('Hydrological_Tibet_G300_trend_vgwstime.nc','z',O.rg);
ncwrite('Hydrological_Tibet_G300_trend_vgwstime.nc','lat',O.lat(:,1));
ncwrite('Hydrological_Tibet_G300_trend_vgwstime.nc','lon',O.lon(1,:));    

后面我发现只要将z写入的O.rg转置一下就行。

nccreate('Hydrological_Tibet_G300_trend_vgwstime.nc','z','Dimensions',{'lon',360,'lat',180},...
    'format','netcdf4','fillvalue','disable','deflatelevel',2);
nccreate('Hydrological_Tibet_G300_trend_vgwstime.nc','lat','dimensions',{'lat',180});
nccreate('Hydrological_Tibet_G300_trend_vgwstime.nc','lon','dimensions',{'lon',360});
ncwrite('Hydrological_Tibet_G300_trend_vgwstime.nc','z',O.rg');
ncwrite('Hydrological_Tibet_G300_trend_vgwstime.nc','lat',O.lat(:,1));
ncwrite('Hydrological_Tibet_G300_trend_vgwstime.nc','lon',O.lon(1,:));    

Matlab写入nc文件遇到‘Start+count exceeds dimension bound (NC_EEDGE)‘问题的解决办法_第1张图片

你可能感兴趣的:(经验分享,matlab,开发语言,经验分享)