problem editing specific variables in a netcdf file using ncwrite

10 views (last 30 days)
I'm trying to edit values in a netcdf file using ncread and ncwrite. For example,
foo = ncread('myfile.nc','x')
Where foo is:
10×1 single column vector
1
2
3
9999
5
6
7
8
9
10
So I want to change the fourth element from 9999 to 4 and write the array back to my netcdf file.
foo(4) = 4
ncwrite('myfile.nc','x',foo)
However, I get the following error:
Error using netcdflib
The NetCDF library encountered an error during execution of 'open' function - 'HDF error (NC_EHDFERR)'.
Error in netcdf.open (line 59)
[varargout{:}] = netcdflib ( 'open', filename, varargin{1} );
Error in internal.matlab.imagesci.nc/openToAppend (line 1238)
this.ncRootid = netcdf.open(this.Filename,'WRITE');
Error in internal.matlab.imagesci.nc (line 123)
this.openToAppend();
Error in ncwrite (line 71)
ncObj = internal.matlab.imagesci.nc(ncFile,'a',formatStr);

Accepted Answer

Zenin Easa Panthakkalakath
Hi Brice,
It appears to be that the NC file specified in the 'filename' variable is not editable. Use the file explorer to have a look into the properties of the file and check if it is 'Read Only'. Also, look into the security tab under properties and see if the current user has the privilege to Modify the file.
Regards,
Zenin

More Answers (0)

Community Treasure Hunt

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

Start Hunting!