How do I append new data to an existing variable in a NETCDF file ?
8 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
MathWorks Support Team
2009-8-14
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!