How to edit a specific variable inside a Netcdf file?

8 次查看(过去 30 天)
Hi guys; I have a netcdf file (.nc) and I would like to do some editing on this file by using matlab. I first use the following command to read the file:
ncid=netcdf.open('GROM-hind-crv-bot-10-05-19-00-thru-10-05-21-00.nc','NC_WRITE');
Then, by using the netcdf.inq(ncid) command:
[numdims numvars numatts unlimdimID] = netcdf.inq(ncid)
I get:
numdims =
3
numvars =
7
numatts =
7
unlimdimID =
2
As shown, there are 7 variables in the section of variables. I want to delete one of the variables. In other words, I want to change number of variables from 7 to 6 by deleting one of them. Could you please help me about that. I am pretty new to netcdf package in Matlab and I do appreciate if everyone could help me about that. Thanks Reza

回答(1 个)

Ashish Uthama
Ashish Uthama 2011-4-1
NetCDF does not let you delete a variable from a file.
Your best bet is to create a new file from the existing one, copying over all BUT the one you want to delete.
  2 个评论
Ashish Uthama
Ashish Uthama 2011-4-12
The 2011a feature |ncwriteschema|: http://www.mathworks.com/help/techdoc/ref/ncwriteschema.html will be useful if you choose to go this route.
Kelly Kearney
Kelly Kearney 2011-4-12
Though if you're going to go the new file method (which I agree is the easiest way to delete a variable, though a bit of a pain if you're working with large files), it's probably easier to use NCO (<http://nco.sourceforge.net/>) than Matlab:
ncks -x -v varToBeDeleted oldfile.nc newfile.nc

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by