ncreadatt
Read attribute from netCDF data source
Description
reads the netCDF attribute attvalue
= ncreadatt(source
,location
,attname
)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 of
attname
. For more information about how MATLAB determines the best match, see NetCDF to MATLAB Data Type Conversion.
Examples
Read Global Attribute
Read the creation_date
global attribute of the netCDF file example.nc
.
creationDate = ncreadatt("example.nc","/","creation_date")
creationDate = '29-Mar-2010'
Read Variable Attribute
Read the scale_factor
attribute associated with the temperature
variable.
scaleFactor = ncreadatt("example.nc","temperature","scale_factor")
scaleFactor = 1.8000
Read Group Attribute
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
source
— Name of netCDF data source
string scalar | character vector
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 readingNote
Byte-range reading is slower than reading from other sources. For more details about byte-range reading, see the netCDF documentation.
Example: "myNetCDFfile.nc"
Example: "http://
host_name
/netcdf_filename
#mode=bytes"
location
— Location of variable or group
string scalar | character vector
Location of a variable or group in the netCDF data source, specified as a string
scalar or character vector. To read a global attribute, set
location
to "/"
(forward slash).
Example: "myVar"
Example: "/myGrp/mySubGrp/myNestedVar"
Example: "myGrp"
Example: "/myGrp/mySubGrp"
attname
— Attribute name
string scalar | character vector
Attribute name to be read, specified as a string scalar or character vector.
Example: "myAttribute"
More About
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 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 format
netcdf4
.
Version History
Introduced in R2011aR2022a: Byte-range reading of remote datasets
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.
R2022a: Read variable length array data types (NC_VLEN
)
You can read variable length array data types (NC_VLEN
) from netCDF-4
files.
R2021b: Read NC_STRING
attributes
You can read NC_STRING
attributes from netCDF-4 files.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)