vardata = ncread(source,varname)
reads all the data from the variable varname contained in the NetCDF file
or an OPeNDAP NetCDF data source specified by source.

vardata = ncread(source,varname,start,count)
reads data beginning at the location specified in start. The
count argument specifies the number of elements to read along each
dimension.

vardata = ncread(source,varname,start,count,stride)
returns data with the interval between the indices of each dimension of the variable
specified by stride.

Read and plot only a subset of the variable data starting from the location [25 17] until the end of each dimension.

startLoc = [25 17]; % Start location along each coordinate
count = [Inf Inf]; % Read until the end of each dimension
peaksData = ncread('example.nc','peaks',startLoc,count);
whos peaksData

Name Size Bytes Class Attributes
peaksData 26x34 1768 int16

Plot the data.

surf(double(peaksData));
title('Peaks Data Starting at [25 17]');

Read Data with Specified Spacing Between Variable Indices

Read and plot data, where the data is sampled at a specified spacing between variable indices along each dimension. Start reading from the location in startLoc and read variable data at intervals specified in stride. A value of 1 in stride, accesses adjacent values in the corresponding dimension. Whereas, a value of 2 accesses every other value in the corresponding dimension, and so on.

Starting location, specified as a numeric vector of positive integers. For an
N-dimensional variable, start is a vector of
length N containing 1-based indices.

If you do not specify start, then the ncread
function starts reading the variable from the first index along each dimension.

Data Types: double

count — Number of elements vector of Inf's (default) | numeric vector

Number of elements to read, specified as a numeric vector of positive integers. For
an N-dimensional variable, count is a vector of
length N, specifying the number of elements to read along each
dimension. If any element of count is Inf, then
ncread reads until the end of the corresponding dimension.

If you do not specify count, then the ncread
function reads the variable data until end of each dimension.

Data Types: double

stride — Space between variable indices vector of ones (default) | numeric vector

Space between the variable indices along each dimension, specified as a numeric
vector of integers. For an N-dimensional variable,
stride is vector of length N. The elements of
the stride vector correspond, in order, to the variable's dimensions.
A value of 1 accesses adjacent values of the NetCDF variable in the
corresponding dimension. Whereas, a value of 2 accesses every other
value of the NetCDF variable in the corresponding dimension, and so on.

If you do not specify stride, then the ncread
function reads the data with a default spacing of 1 along each
dimension.

Variable data, returned as text or numeric arrays.

In most cases, the ncread function uses the MATLAB^{®} datatype that is the closest type to the corresponding NetCDF
datatype.

When at least one of the variable attributes _FillValue,
scale_factor, or add_offset is present, then
ncread returns vardata of type
double. In addition, ncread applies these
conventions:

If the _FillValue attribute exists, then
ncread replaces vardata values equal to
_FillValue values with NaNs. If
the_FillValue attribute does not exist, then
ncread queries the NetCDF library for the variable's fill
value.

If the scale_factor attribute exists, then
ncread multiplies variable data by the value of the
scale_factor attribute.

If the add_offset attribute exists, then
ncread adds the value of the add_offset
attribute to the variable data.

Note

For variable data containing text, the ncread function supports
reading only of vardata that is ASCII encoded.

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.