MATLAB: How to overwrite the NETCDF4 file in MATLAB

clobberMATLABnetcdfnetcdf.createoverwrite

I am trying to create a NETCDF4 file using NETCDF.CREATE function in MALTAB. The documentation says that two modes can be used in combination by using a BITOR of their respective integers, but when I use CLOBBER mode along with NETCDF4 mode I still can't overwrite my file and MATLAB throws an error message.

Best Answer

This error occurs when the netCDF file was not closed before attempting to overwrite it. The file needs to be properly closed first using netcdf.close, before calling netcdf.create to overwrite it.
The following code snippet illustrates the correct way to proceed:
mode = netcdf.getConstant('CLOBBER');
mode = bitor(mode, netcdf.getConstant('NETCDF4'));
fileID = netcdf.create('file1.nc', mode);
netcdf.close(fileID);
fileID = netcdf.create('file1.nc', mode);
With this:
>> fileID
fileID =
65536