Saturday, July 25, 2009

continued..

cdfread

Read data from a CDF file

Syntax

  • data = cdfread(file)
    data = cdfread(file, 'records', recnums, ...)
    data = cdfread(file, 'variables', varnames, ...)
    data = cdfread(file, 'slices', dimensionvalues, ...)
    [data, info] = cdfread(file, ...)

Description

data = cdfread(file) reads all of the variables from each record of the Common Data Format (CDF) file specified in the string, file. The return value, data, is a cell array in which each row contains a record and each column represents a variable.

data = cdfread(file, 'records', recnums, ...) reads only those records specified in the vector, recnums. The record numbers are zero-based. The return value, data, is a cell array having length(recnums) number of rows and as many columns as there are variables.

data = cdfread(file, 'variables', varnames, ...) reads only those variables specified in the 1-by-N or N-by-1 cell array of strings, varnames. The return alue, data, is returned in a cell array having length(varnames) number of columns and a row for each record requested.

data = cdfread(file, 'slices', dimensionvalues, ...) reads specific values from the records of one variable in the CDF file. The N-by-3 matrix, dimensionvalues, indicates which records are to be read by specifying start, interval, and count parameters for each of the N dimensions of the variable. The start parameter is zero-based.

The number of rows in dimensionvalues must be less than or equal to the number of dimensions of the variable. Unspecified rows default to [0 1 N], where N is the total number of values in a record. This causes cdfread to read every value from those dimensions.

Because you can read just one variable at a time, you must also include a 'variables' parameter with this syntax.

[data, info] = cdfread(file, ...) also returns details about the CDF file in the info structure.

Examples

Read all of the data from the file.

  • data = cdfread('example.cdf');

Read just the data from variable 'Time'.

  • data = cdfread('example.cdf', 'Variable', {'Time'});

Read the first value in the first dimension, the second value in the second dimension, the first and third values in the third dimension, and all values in the remaining dimension of the variable 'multidimensional'.

  • data = cdfread('example.cdf', 'Variable', ...
    {'multidimensional'}, 'Slices', [0 1 1; 1 1 1; 0 2 2]);

This is similar to reading the whole variable into 'data', and then using the MATLAB command

  • data{1}(1, 2, [1 3], :)

cdfwrite

Write data to a CDF file

Syntax

  • cdfwrite(file, variablelist)
    cdfwrite(..., 'PadValues', padvals)
    cdfwrite(..., 'GlobalAttributes', gattrib)
    cdfwrite(..., 'VariableAttributes', vattrib)
    cdfwrite(..., 'WriteMode', mode)
    cdfwrite(..., 'Format', format)

Description

cdfwrite(file,variablelist) writes out a Common Data Format (CDF) file, specified in the string, file. The variablelist argument is a cell array of ordered pairs, which are comprised of a CDF variable name (a string) and the corresponding CDF variable value. To write out multiple records for a variable, put the values in a cell array, where each element in the cell array represents a record.

cdfwrite(...,'PadValues',padvals) writes out pad values for given variable names. padvals is a cell array of ordered pairs, which are comprised of a variable name (a string) and a corresponding pad value. Pad values are the default value associated with the variable when an out-of-bounds record is accessed. Variable names that appear in padvals must appear in variablelist.

cdfwrite(...,'GlobalAttributes',gattrib) writes the structure gattrib as global metadata for the CDF file. Each field of the structure is the name of a global attribute. The value of each field contains the value of the attribute. To write out multiple values for an attribute, put the values in a cell array where each element in the cell array represents a record.

    Note To specify a global attribute name that is illegal in MATLAB, create a field called 'CDFAttributeRename' in the attribute structure. The value of this field must have a value that is a cell array of ordered pairs. The ordered pair consists of the name of the original attribute, as listed in the GlobalAttributes structure and the corresponding name of the attribute to be written to the CDF file.

cdfwrite(..., 'VariableAttributes', vattrib) writes the structure vattrib as variable metadata for the CDF. Each field of the struct is the name of a variable attribute. The value of each field should be an M-by-2 cell array where M is the number of variables with attributes. The first element in the cell array should be the name of the variable and the second element should be the value of the attribute for that variable.

    Note To specify a variable attribute name that is illegal in MATLAB, create a field called 'CDFAttributeRename' in the attribute structure. The value of this field must have a value that is a cell array of ordered pairs. The ordered pair consists of the name of the original attribute, as listed in the VariableAttributes struct, and the corresponding name of the attribute to be written to the CDF file. If you are specifying a variable attribute of a CDF variable that you are renaming, the name of the variable in the VariableAttributes structure must be the same as the renamed variable.

cdfwrite(...,'WriteMode',mode) where mode is either 'overwrite' or 'append', indicates whether or not the specified variables should be appended to the CDF file if the file already exists. By default, cdfwrite overwrites existing variables and attributes.,

cdfwrite(...,'Format',format) where format is either 'multifile' or 'singlefile', indicates whether or not the data is written out as a multifile CDF. In a multifile CDF, each variable is stored in a separate file with the name *.vN, where N is the number of the variable that is written out to the CDF. By default, cdfwrite writes out a single file CDF. When 'WriteMode' is set to 'Append', the 'Format' option is ignored, and the format of the pre-existing CDF is used.

Examples

Write out a file 'example.cdf' containing a variable 'Longitude' with the value [0:360].

  • cdfwrite('example', {'Longitude', 0:360});

Write out a file 'example.cdf' containing variables 'Longitude' and 'Latitude' with the variable 'Latitude' having a pad value of 10 for all out-of-bounds records that are accessed.

  • cdfwrite('example', {'Longitude', 0:360, 'Latitude', 10:20},...
    'PadValues', {'Latitude', 10});

Write out a file 'example.cdf', containing a variable 'Longitude' with the value [0:360], and with a variable attribute of 'validmin' with the value 10.

  • varAttribStruct.validmin = {'longitude' [10]};
    cdfwrite('example', {'Longitude' 0:360}, 'VarAttribStruct',...
    varAttribStruct);
ceil

Round toward infinity

Syntax

  • B = ceil(A)

Description

B = ceil(A) rounds the elements of A to the nearest integers greater than or equal to A. For complex A, the imaginary and real parts are rounded independently.

Examples

  • a = [-1.9, -0.2, 3.4, 5.6, 7, 2.4+3.6i]

    a =
    Columns 1 through 4
    -1.9000 -0.2000 3.4000 5.6000

    Columns 5 through 6
    7.0000 2.4000 + 3.6000i

    ceil(a)

    ans =
    Columns 1 through 4
    -1.0000 0 4.0000 6.0000

    Columns 5 through 6
    7.0000 3.0000 + 4.0000i

No comments:

Post a Comment