| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
data = netcdf.getVar(ncid,varid)
data = netcdf.getVar(ncid,varid,start)
data = netcdf.getVar(ncid,varid,start,count)
data = netcdf.getVar(ncid,varid,start,count,stride)
data = netcdf.getVar(...,output_type)
data = netcdf.getVar(ncid,varid) returns data, the value of the variable specified by varid. MATLAB attempts to match the class of the output data to netCDF class of the variable.
ncid is a netCDF file identifier returned by netcdf.create or netcdf.open.
data = netcdf.getVar(ncid,varid,start) returns a single value starting at the specified index, start.
data = netcdf.getVar(ncid,varid,start,count) returns a contiguous section of a variable. start specifies the starting point and count specifies the amount of data to return.
data = netcdf.getVar(ncid,varid,start,count,stride) returns a subset of a section of a variable. start specifies the starting point, count specifies the extent of the section, and stride specifies which values to return.
data = netcdf.getVar(...,output_type) specifies the data type of the return value data. For example, to read in an entire integer variable as double precision, use:
data=netcdf.getVar(ncid,varid,'double');
You can specify any of the following strings for the output data type.
| 'int' | 'double' | 'int16' |
| 'short' | 'single' | 'int8' |
| 'float' | 'int32' | 'uint8' |
This function corresponds to several functions in the netCDF library C API. To use this function, you should be familiar with the information about netCDF contained in the NetCDF C Interface Guide for version 3.6.2.
This example opens the example netCDF file included with MATLAB, example.nc, and uses several functions to get the value of a variable.
% Open example file.
ncid = netcdf.open('example.nc','NC_NOWRITE');
% Get the name of the first variable.
[varname, xtype, varDimIDs, varAtts] = netcdf.inqVar(ncid,0);
% Get variable ID of the first variable, given its name.
varid = netcdf.inqVarID(ncid,varname);
% Get the value of the first variable, given its ID.
data = netcdf.getVar(ncid,varid)
data =
6.0221e+023netcdf.create ,netcdf.inqVarID, netcdf.open
![]() | netcdf.getConstantNames | netcdf.inq | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |