Skip to Main Content Skip to Search
Product Documentation

ncwriteatt - Write attribute to NetCDF file

Syntax

ncwriteatt(filename,location,attname,attvalue)

Description

ncwriteatt(filename,location,attname,attvalue) creates or modifies the attribute specified by attname in the group or variable specified by location, in the NetCDF file specified by filename. attvalue can be a numeric vector or a string.

Input Arguments

filename

Text string specifying the name of a NetCDF file

location

Text string specifying a group or variable in the NetCDF file. To write global attributes, set location to '/' (forward slash).

attname

Text string specifying the name of an existing attribute in a NetCDF file or the name of the attribute that you want to create.

attvalue

Numeric vector or a string.

Examples

Create a global attribute.

copyfile(which('example.nc'),'myfile.nc');
fileattrib('myfile.nc','+w');
ncdisp('myfile.nc');
ncwriteatt('myfile.nc','/','creation_date',datestr(now));
ncdisp('myfile.nc');
 

Modify an existing attribute.

copyfile(which('example.nc'),'myfile.nc');
fileattrib('myfile.nc','+w');
ncdisp('myfile.nc','peaks');
ncwriteatt('myfile.nc','peaks','description','Output of PEAKS');
ncdisp('myfile.nc','peaks');

See Also

nccreate | ncdisp | ncread | ncreadatt | ncwrite | netcdf

Tutorials

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS