%% Open NetCDF File for Writing
% Open an NetCDF and assign a value to a variable, and then display it.
% Create NetCDF File myexample.nc containing a variable pi.

nccreate('myexample.nc','pi')

% Open the file for writing and write the value 3.1416 to the variable pi.

ncid = netcdf.open('myexample.nc','WRITE')
varInd = 0; % index of the first variable in the file
varValue = 3.1416 ; 
netcdf.putVar(ncid,varInd,varValue);

% Read and display the value of the variable pi from the file.

netcdf.getVar(ncid,varInd)

% Close the file.

netcdf.close(ncid);

% Copyright 2018 The MathWorks, Inc.