How do I append new data to an existing variable in a NETCDF file ?
8 views (last 30 days)
Show older comments
I need to append some data to an existing variable in a netcdf file (.nc file). Say, if I have created a netcdf file as follows,
% Create a 50 element vector for a variable.
my_vardata = linspace(0,50,50);
% Open netCDF file.
ncid = netcdf.create('foo.nc','NC_WRITE')
% Define the dimensions of the variable.
dimid = netcdf.defDim(ncid,'my_dim',50);
% Define a new variable in the file.
my_varID = netcdf.defVar(ncid,'my_var','double',dimid)
% Leave define mode and enter data mode to write data.
netcdf.endDef(ncid)
% Write data to variable.
netcdf.putVar(ncid,my_varID,my_vardata);
Now I want to open the file and append the some new data, say new_data=(51:100) to my_vardata in the file. How can I achieve this?
Accepted Answer
MathWorks Support Team
on 14 Aug 2009
It is possible to append new data to an existing variable in a netcdf file. To make this possible, the dimension of the variable must be defined as NC_UNLIMITED. This is demonstrated using the attached MATLAB file "appendnewdata.m".
0 Comments
More Answers (0)
See Also
Categories
Find more on NetCDF in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!