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!