This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Copy attribute to new location




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 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.


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

% Open example file.
ncid ='','NC_NOWRITE');

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

% Create new netCDF file.
ncid2 = netcdf.create('','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.
% Check the name of the attribute in new file.
attname = netcdf.inqAttName(ncid2,varid2,0)

attname =

Was this topic helpful?