ncreadatt

Read attribute value from NetCDF data source

Syntax

attvalue = ncreadatt(source,location,attname)

Description

attvalue = ncreadatt(source,location,attname) reads the attribute attname from the group or variable specified by location in source, where source is the name of a NetCDF file or the URL of a NetCDF data source.

Input Arguments

source

Character vector or string scalar specifying the name of a NetCDF file or the URL of an OPeNDAP NetCDF data source.

location

Character vector or string scalar specifying a group or variable in the NetCDF data source. To read global attributes, set location to '/' (forward slash).

attname

Character vector or string scalar specifying the name of an attribute that you want to read in the NetCDF data source.

Output Arguments

attvalue

Data associated with the attribute.

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 netcdf4 format files only.

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