MATLAB Answers

How do I append new data to an existing variable in a NETCDF file ?

41 views (last 30 days)
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('','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.
% Write data to variable.
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
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".

More Answers (0)


Community Treasure Hunt

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

Start Hunting!