Main Content

ncreadatt

Read attribute value from NetCDF data source

Description

example

attvalue = ncreadatt(source,location,attname) reads the attribute attname from the group or variable specified by location in source. The returned attribute value attvalue is of the MATLAB® data type that best matches the NetCDF data type of attname. For more information about how MATLAB determines the best match, see More About.

Examples

collapse all

creation_date = ncreadatt("example.nc","/","creation_date")
creation_date = 
'29-Mar-2010'

Read an attribute associated with a variable.

scale_factor = ncreadatt("example.nc","temperature","scale_factor")
scale_factor = 1.8000

Read an attribute associated with a group. This example applies to NetCDF-4 format files only.

desc_value = ncreadatt("example.nc","/grid2","description")
desc_value = 
'This is another group attribute.'

Input Arguments

collapse all

Name of the NetCDF data source, specified as a string scalar or character vector. The source argument can be one of these values:

  • The path of a local NetCDF source

  • The OPeNDAP URL of a remote OPeNDAP NetCDF data source

  • The HTTP URL of a remote NetCDF source, with #mode=bytes appended to the end of the URL to enable byte-range reading

    Note

    Byte-range reading is slower than reading from other sources. For more details about byte-range reading, see the NetCDF documentation.

Example: "myNetCDFfile.nc"

Location of group or variable in the NetCDF data source, specified as a string scalar or character vector. To read a global attribute, set location to '/' (forward slash).

Attribute name to be read, specified as a string scalar or character vector.

More About

collapse all

NetCDF to MATLAB Data Type Conversion

The NetCDF-related MATLAB functions automatically choose the MATLAB data type that best matches the NetCDF data type according to this table.

NetCDF Data TypeMATLAB Data Type
NC_DOUBLEdouble
NC_FLOATsingle
NC_INT64 (NetCDF-4 files only)int64
NC_UINT64 (NetCDF-4 files only)uint64
NC_INTint32
NC_UINT (NetCDF-4 files only)uint32
NC_SHORTint16
NC_USHORT (NetCDF-4 files only)uint16
NC_BYTEint8
NC_UBYTE (NetCDF-4 files only)uint8
NC_CHARchar
NC_STRING (NetCDF-4 files only)string
User-defined NC_VLEN types (NetCDF-4 files only)cell

Version History

Introduced in R2011a

expand all