How to edit a specific variable inside a Netcdf file?

조회 수: 5 (최근 30일)
Reza Madankan
Reza Madankan 2011년 3월 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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by