ncread - Read data from variable in NetCDF data source
Syntax
vardata = ncread(source,varname)
vardata = ncread(source,varname,start,count,stride)
Description
vardata = ncread(source,varname) reads
data from the variable varname in source,
which can be either the name of a NetCDF file or an OPeNDAP NetCDF
data source.
vardata = ncread(source,varname,start,count,stride) reads
data from the variable varname in source beginning
at the location given by start. count specifies
the number of elements to read along the corresponding dimension.
The optional argument stride specifies the inter-element
spacing along each dimension.
Input Arguments
source |
Text string specifying the name of a NetCDF file or the URL
of an OPeNDAP NetCDF data source.
|
varname |
Text string specifying the name of a variable in the NetCDF
file or OPeNDAP NetCDF data source.
|
start |
For an N-dimensional variable, start is
a vector of length N of indices specifying the
starting location. Indices are 1-based.
|
count |
Vector of length N specifying the number
of elements to read along the corresponding dimensions. If a particular
element of count is Inf, ncread reads
data until the end of the corresponding dimension.
|
stride |
Optional argument that specifies the inter-element spacing along
each dimension. Default: Vector of 1s (ones) |
Output Arguments
vardata |
The data in the variable. ncread uses the MATLAB datatype
that is the closest type to the corresponding NetCDF datatype, except
when at least one of _FillValue, scale_offset,
and add_offset variables attribute is present. ncread applies
the following attribute conventions, in sequence, to vardata if
the corresponding attribute exists for this variable:
If the _FillValue attribute exists, ncread replaces
values in vardata equal to value of _FillValue with NaNs.
If the_FillValue' attribute does not exist, ncread queries
the NetCDF library for the variable's fill value. If the scale_factor attribute exists, ncread multiplies vardata by
the value of thescale_factor' attribute If the add_offset attribute exists, ncread adds
the value of the add_offset' attribute to vardata.
|
Examples
Read and display the data in the peaks variable
in the example file.
ncdisp('example.nc','peaks');
peaksData = ncread('example.nc','peaks');
peaksDesc = ncreadatt('example.nc','peaks','description');
surf(double(peaksData));
title(peaksDesc);Subsample the peaks data by a factor of 2 (read every other
value along each dimension).
subsetdata = ncread('example.nc','peaks',...
[1 1], [Inf Inf], [2 2]);
surf(double(subsetdata));See Also
ncdisp | ncinfo | ncreadatt | ncwrite | netcdf
Tutorials