ncreadatt - Read attribute from netCDF data source - MATLAB (original) (raw)
Main Content
Read attribute from netCDF data source
Syntax
Description
`attvalue` = ncreadatt([source](#mw%5F541d6a5c-1c73-4301-a9a9-047dbbe46b2f%5Fsep%5Fmw%5Fe339e1a9-285c-4606-9ca3-5d590980a4d2),[location](#mw%5Ff1c4179d-52c1-4dd3-afe2-ca60cd0dd175),[attname](#mw%5Feaf8bc1e-33fa-416c-9c5a-4e505c65c6e2))
reads the netCDF attribute attname
from the group or variable specified by location
in source
. The returned attribute value is of the MATLABĀ® data type that best matches the netCDF data type ofattname
. For more information about how MATLAB determines the best match, see NetCDF to MATLAB Data Type Conversion.
Examples
Read the creation_date
global attribute of the netCDF file example.nc
.
creationDate = ncreadatt("example.nc","/","creation_date")
creationDate = '29-Mar-2010'
Read the scale_factor
attribute associated with the temperature
variable.
scaleFactor = ncreadatt("example.nc","temperature","scale_factor")
Read the description
attribute associated with the /grid2
group. You can read group attributes from files with format netcdf4
only.
groupDescription = ncreadatt("example.nc","/grid2","description")
groupDescription = 'This is another group attribute.'
Input Arguments
Name of the netCDF data source, specified as a string scalar or character vector. Thesource
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 other methods for reading from remote sources. For more details about byte-range reading, see the netCDF documentation.
Example: "myNetCDFfile.nc"
Example: "http://_`hostname`_/_`netcdffilename`_#mode=bytes"
Location of a variable or group in the netCDF data source, specified as a string scalar or character vector. To read a global attribute, setlocation
to "/"
(forward slash).
Example: "myVar"
Example: "/myGrp/mySubGrp/myNestedVar"
Example: "myGrp"
Example: "/myGrp/mySubGrp"
Attribute name to be read, specified as a string scalar or character vector.
Example: "myAttribute"
More About
The netCDF-related MATLAB functions automatically choose the MATLAB data type that best matches the netCDF data type according to this table.
NetCDF Data Type | MATLAB Data Type |
---|---|
NC_DOUBLE | double |
NC_FLOAT | single |
NC_INT | int32 |
NC_SHORT | int16 |
NC_BYTE | int8 |
NC_CHAR | char |
NC_STRING (*) | string |
NC_INT64 (*) | int64 |
NC_UINT64 (*) | uint64 |
NC_UINT (*) | uint32 |
NC_USHORT (*) | uint16 |
NC_UBYTE (*) | uint8 |
User-defined NC_VLEN types (*) | cell |
(*) These netCDF data types are available only for files with formatnetcdf4
.
Tips
- The
ncreadatt
function returns attributes that are vectors as row vectors.
Version History
Introduced in R2011a
You can use ncreadatt
for read-only access to remote datasets using the HTTP byte-range capability, provided that the remote server supports byte-range access.
You can read variable length array data types (NC_VLEN
) from netCDF-4 files.
You can read NC_STRING
attributes from netCDF-4 files.