Error in reading variables in netcdf files
2 views (last 30 days)
Show older comments
Joydeb Saha
on 7 Mar 2024
Answered: Walter Roberson
on 7 Mar 2024
javaaddpath('D:\SHUM\NetCDF file read\netcdf souceforge\mexcdf\netcdfAll-4.2.jar');
javaaddpath('D:\SHUM\NetCDF file read\netcdf souceforge\mexcdf\snctools\classes');
addpath ('D:\SHUM\NetCDF file read\netcdf souceforge\mexcdf\snctools');
addpath ('D:\SHUM\NetCDF file read\netcdf souceforge\mexcdf\mexnc');
addpath ('D:\SHUM\NetCDF file read\netcdf souceforge\mexcdf\netcdf_toolbox')
addpath ('D:\SHUM\NetCDF file read\netcdf souceforge\mexcdf\netcdf_toolbox\netcdf\ncsource')
addpath('D:\SHUM\NetCDF file read\netcdf souceforge\mexcdf\netcdf_toolbox\netcdf\nctype')
addpath('D:\SHUM\NetCDF file read\netcdf souceforge\mexcdf\netcdf_toolbox\netcdf\ncutility')
addpath('D:\SHUM\NetCDF file read\netcdf souceforge\mexcdf\netcdf_toolbox\netcdf')
myFolder ='E:\ERA5\U\U_Clim_1987_2016\U_06';
filePattern = fullfile(myFolder, '*.nc');
Files = dir(filePattern);
% for k= 1:length(Files)
k=1;
baseFileName = Files(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
data_specific=netcdf.open(fullFileName);
ncid = netcdf.open(fullFileName,'NC_NOWRITE');
varid_spe = netcdf.inqVarID(ncid,'u10');
scale_factor_spe = netcdf.getAtt(ncid,varid_spe,'scale_factor');
add_ofset_spe=netcdf.getAtt(ncid,varid_spe,'add_offset');
fill_value_spe=netcdf.getAtt(ncid,varid_spe,'_FillValue');
unit=netcdf.getAtt(ncid,varid_spe,'units');
long_name=netcdf.getAtt(ncid,varid_spe,'long_name');
lat=data_specific{'latitude'}(:);
lon1=data_specific{'longitude'}(:);
time=data_specific{'time'}(:);
>> lat=data_specific{'latitude'}(:);
Brace indexing is not supported for variables of this type. I found this type of error
0 Comments
Accepted Answer
Walter Roberson
on 7 Mar 2024
data_specific=netcdf.open(fullFileName);
%...
lat=data_specific{'latitude'}(:);
data_specific will be an ncid (netcdf identifier -- an integer)
There is no documented syntax for using {} indexing of an ncid.
You have to use things such as netcdf.getvar()
0 Comments
More Answers (0)
See Also
Categories
Find more on NetCDF in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!