%% Write Data to Portion of Variable
% Write data to a portion of a variable in a NetCDF file starting at a specified location.
% Create a file myncfile.nc with an empty 3-by-6 numeric variable vmark. To disable the default fill value for missing or empty variables, set the value of the FillValue name-value pair argument to disable.

nccreate('myncfile.nc','vmark',...
         'Dimensions', {'x',3,'y',6},...
         'FillValue','disable');     

% Write a 3-by-3 array to the variable, and then read and display vmark from the file. The ncwrite function writes data starting at the beginning of the variable.

ncwrite('myncfile.nc','vmark',3*eye(3));
varData = ncread('myncfile.nc','vmark');
display(varData)

% Add another 3-by-3 array to the variable vmark starting at the fourth column of the first row. Next, read and display vmark from the file. The ncrwrite function writes the array starting at the location [1 4].

ncwrite('myncfile.nc','vmark',5*eye(3),[1 4]);
varData = ncread('myncfile.nc','vmark');
display(varData)

% Copyright 2018 The MathWorks, Inc.