Main Content


Return ID associated with variable name


varid = netcdf.inqVarID(ncid,varname)


varid = netcdf.inqVarID(ncid,varname) returns varid corresponding to varname. Specify varname as character vector or string scalar.

ncid is a netCDF file identifier returned by netcdf.create or

This function corresponds to the nc_inq_varid function in the netCDF library C API. To use this function, you should be familiar with the netCDF programming paradigm.


This example opens the example netCDF file included with MATLAB®,, and uses several inquiry functions to get the ID of the first variable.

ncid ='','NC_NOWRITE');

% Get information about first variable in the file.
[varname, xtype, dimids, atts] = netcdf.inqVar(ncid,0);

% Get variable ID of the first variable, given its name
varid = netcdf.inqVarID(ncid,varname)

varid =