Main Content

ncreadatt

Read attribute value from NetCDF data source

Syntax

attvalue = ncreadatt(source,location,attname)

Description

attvalue = ncreadatt(source,location,attname)reads the attributeattnamefrom the group or variable specified bylocationinsource, where source is the name of a NetCDF file, the URL of a NetCDF data source, or the HTTP URL of a remote NetCDF file (with the#mode=bytessuffix for byte-range reading).

Input Arguments

source

Character vector or string scalar specifying the name of a NetCDF file, the URL of an OPeNDAP NetCDF data source, or an HTTP URL of a remote NetCDF file for byte-range reading. To enable byte-range reading of remote datasets, append#mode=bytesto the end of the HTTP URL. For details about byte-range reading, consult the NetCDF documentation.

Example:"myNetCDFfile.nc"

location

Character vector or string scalar specifying a group or variable in the NetCDF data source. To read global attributes, setlocationto'/'(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 NetCDF-4 format files only.

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

Limitations

  • The performance of byte-range reading is slower than reading from other sources.

版本历史

Introduced in R2011a