Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

netcdf.defVar - Create netCDF variable

Syntax

varid = netcdf.defVar(ncid,varname,xtype,dimids)

Description

varid = netcdf.defVar(ncid,varname,xtype,dimids) creates a new variable in the dataset identified by ncid.

varname is a character string that specifies the name of the variable. xtype can be either a character string specifying the data type of the variable, such as 'double', or it can be the numeric equivalent returned by the netcdf.getConstant function. dimids specifies a list of dimension IDs.

netcdf.defVar returns varid, a numeric identifier for the new variable.

This function corresponds to the nc_def_var function in the netCDF library C API. Because MATLAB uses FORTRAN-style ordering, the fastest-varying dimension comes first and the slowest comes last. Any unlimited dimension is therefore last in the list of dimension IDs. This ordering is the reverse of that found in the 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.

Examples

This example creates a new netCDF file, defines a dimension in the file, and then defines a variable on that dimension. (In netCDF files, you must create a dimension before you can create a variable.) To run this example, you must have write permission in your current directory.

% Create  netCDF file.
ncid = netcdf.create('foo.nc','NC_NOCLOBBER');
%
% Define a dimension in the new file.
dimid = netcdf.defDim(ncid,'x',50);

% Define a variable in the new file.
varid = netcdf.defVar(ncid,'myvar','double',dimid)

See Also

netCDF.getConstant, netCDF.inqVar, netCDF.putVar

  


Recommended Products

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