Error in reading variables in netcdf files

3 views (last 30 days)
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

Accepted Answer

Walter Roberson
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()

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!