Skip to Main Content Skip to Search
Product Documentation

netcdf.copyAtt - Copy attribute to new location

Syntax

netcdf.copyAtt(ncid_in,varid_in,attname,ncid_out,varid_out)

Description

netcdf.copyAtt(ncid_in,varid_in,attname,ncid_out,varid_out) copies an attribute from one variable to another, possibly across files. ncid_in and ncid_out are netCDF file identifiers returned by netcdf.create or netcdf.open. varid_in identifies the variable with an attribute that you want to copy. varid_out identifies the variable to which you want to associate a copy of the attribute.

This function corresponds to the nc_copy_att function in the netCDF library C API. To use this function, you should be familiar with the netCDF programming paradigm. See netcdf for more information.

Examples

This example makes a copy of the attribute associated with the first variable in the netCDF example file, example.nc, in a new file. To run this example, you must have write permission in your current directory.

% Open example file.
ncid = netcdf.open('example.nc','NC_NOWRITE');

% Get identifier for a variable in the file.
varid = netcdf.inqVarID(ncid,'avagadros_number');

% Create new netCDF file.
ncid2 = netcdf.create('foo.nc','NC_NOCLOBBER');

% Define a dimension in the new file.
dimid2 = netcdf.defDim(ncid2,'x',50);

% Define a variable in the new file.
varid2 = netcdf.defVar(ncid2,'myvar','double',dimid2);

% Copy the attribute named 'description' into the new file,
% associating the attribute with the new variable.
netcdf.copyAtt(ncid,varid,'description',ncid2,varid2);
%
% Check the name of the attribute in new file.
attname = netcdf.inqAttName(ncid2,varid2,0)

attname =

description

See Also

netcdf.inqAtt | netcdf.inqAttID | netcdf.inqAttName | netcdf.putAtt | netcdf.renameAtt

  


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