cdflib.createVar
Create new variable
Syntax
varnum = cdflib.createVar(cdfId,
varname
,
datatype, numElements, dims, recVariance, dimVariance)
Description
varnum = cdflib.createVar(cdfId,
creates a new variable in the Common Data Format (CDF) file with the
specified characteristics. varname
,
datatype, numElements, dims, recVariance, dimVariance)
Input Arguments
|
Identifier of a CDF file, returned by a call to | ||||||||||||||||||||||||||||||||
|
Character vector or string scalar that specifies the name you want to assign to the variable. | ||||||||||||||||||||||||||||||||
|
Data type of the variable, specified as one of the following character vectors or string scalars containing a valid CDF data type, or its numeric equivalent.
| ||||||||||||||||||||||||||||||||
|
Number of elements per datum. Value should be 1 for all data
types, except for | ||||||||||||||||||||||||||||||||
|
A vector of the dimensions extents; empty if there are no dimension extents. | ||||||||||||||||||||||||||||||||
|
Specifies record variance: | ||||||||||||||||||||||||||||||||
|
A vector of logicals; empty if there are no dimensions. |
Output Arguments
|
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 = struct with fields: 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 = struct with fields: encoding: 'IBMPC_ENCODING' majority: 'ROW_MAJOR' maxRec: -1 numVars: 1 numvAttrs: 0 numgAttrs: 0
% Clean up cdflib.delete(cdfId) clear cdfId
Tips
This function corresponds to the CDF library C API routine
CDFcreatezVar
.To use this function, you must be familiar with the CDF C interface. You can access the CDF documentation at the CDF website.