Cannot read NC file dimensions values and regrid them
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm trying tot rescale coordinates in the .nc file that has one variable.
ncfile = 'my_file.nc';
ncdisp(ncfile) produces this result;
Format: netcdf4_classic
Dimensions:
lat = 234
lon = 288
Variables:
var
Size: 234x288
Dimensions: lat,lon
Datatype: double
info = ncinfo(ncfile);
dim_lat = info.Variables(strcmp({info.Variables.Name}, 'swr')).Dimensions(strcmp({info.Variables(strcmp({info.Variables.Name}, 'var')).Dimensions.Name}, 'lat')).Name;
dim_lon = info.Variables(strcmp({info.Variables.Name}, 'swr')).Dimensions(strcmp({info.Variables(strcmp({info.Variables.Name}, 'var')).Dimensions.Name}, 'lon')).Name;
But then I'm getting an error when I'm trying to read the values:
lat_existing = ncread(ncfile, dim_lat);
lon_existing = ncread(ncfile, dim_lon);
Error using internal.matlab.imagesci.nc/getGroupAndVarid
Could not find variable or group 'lat' in file.
Error in internal.matlab.imagesci.nc/read (line 648)
[gid, varid] = getGroupAndVarid(this, location);
Error in ncread (line 76)
vardata = ncObj.read(varName, varargin{:});
0 个评论
采纳的回答
MJFcoNaN
2024-2-28
编辑:MJFcoNaN
2024-2-28
Hello,
"ncread" can only get a variable not a dimention.
There is only a length of any "Dimention", such as lat=234, but no value.
In many cases, you will find some variables under the same or different name with the dimentions, then you can use ncread to get them. For my fake example, ncread(ncfile, "lat"), ncread(ncfile, "longitude") and ncread(ncfile, "lat_matrix") will get the value:
Format: netcdf4_classic
Dimensions:
lat = 234
lon = 288
Variables:
var
Size: 234x288
Dimensions: lat,lon
Datatype: double
lat
Size: 234
Dimensions: lat
Datatype: double
longitude
Size: 288
Dimensions: lon
Datatype: double
lat_matrix
Size: 234x288
Dimensions: lat,lon
Datatype: double
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Triangulation Representation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!