Skip to Main Content Skip to Search
Product Documentation

cdflib.createVar - Create new variable

Syntax

varnum = cdflib.createVar(cdfId, varname, datatype, numElements, dims, recVariance, dimVariance)

Description

varnum = cdflib.createVar(cdfId, varname, datatype, numElements, dims, recVariance, dimVariance) creates a new variable in the Common Data Format (CDF) file with the specified characteristics.

Input Arguments

cdfId

Identifier of a CDF file, returned by a call to cdflib.create or cdflib.open.

varname

Text string that specifies the name you want to assign to the variable.

datatype

Data type of the variable. One of the following text strings, or its numeric equivalent, that specifies a valid CDF data type.

CDF Data TypeDescription
CDF_BYTE1-byte, signed integer
CDF_CHAR1 byte, signed character data type that maps to the MATLABchar class
CDF_INT11-byte, signed integer
CDF_UCHAR1 byte, unsigned character data type that maps to the MATLABuint8 class
CDF_UINT11-byte, unsigned integer
CDF_INT22-byte, signed integer
CDF_UINT22-byte, unsigned integer
CDF_INT44-byte, signed integer
CDF_UINT44-byte, unsigned integer
CDF_FLOAT4-byte, floating point
CDF_REAL44-byte, floating point
CDF_REAL88-byte, floating point.
CDF_DOUBLE8-byte, floating point
CDF_EPOCH8-byte, floating point
CDF_EPOCH16two 8-byte, floating point

numElements

Number of elements per datum. Value should be 1 for all data types, except CDF_CHAR and CDF_UCHAR.

dims

A vector of the dimensions extents; empty if there are no dimension extents.

recVariance

Specifies record variance: true or false.

dimVariance

A vector of logicals; empty if there are no dimensions.

Output Arguments

varNum

The numeric identifier for the variable. Variable numbers are zero-based.

Examples

Create a CDF file and then create a variable named 'Time' in the CDF. The variable has no dimensions and varies across records. To run this example, you must be in a writable folder.

cdfid = cdflib.create('your_file.cdf');

% Initially the file contains no variables.
info = cdflib.inquire(cdfid)

info = 

     encoding: 'IBMPC_ENCODING'
     majority: 'ROW_MAJOR'
       maxRec: -1
      numVars: 0
    numvAttrs: 0
    numgAttrs: 0

% Create a variable in the file.
varNum = cdflib.createVar(cdfid,'Time','cdf_int1',1,[],true,[]);

% Retrieve info about the file again to verify variable was created. 
% Note value of numVars field is now 1.
info = cdflib.inquire(cdfid)

info = 

     encoding: 'IBMPC_ENCODING'
     majority: 'ROW_MAJOR'
       maxRec: -1
      numVars: 1
    numvAttrs: 0
    numgAttrs: 0

% Clean up
cdflib.delete(cdfid);

clear cdfid

References

This function corresponds to the CDF library C API routine CDFcreatezVar. To use these functions, you must be familiar with the CDF C interface. Read the CDF documentation at the CDF Web site. For copyright information, see the cdfcopyright.txt file.

See Also

cdflib.closeVar | cdflib.deleteVar

Tutorials

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS