MATLAB Application Program Interface
  Go to function:
    Search    Help Desk 
mxGetScalar    Examples   See Also

Get the real component of an mxArray's first data element

C Syntax

Arguments

array_ptr
  Pointer to an mxArray other than a cell mxArray or a structure mxArray.

Returns

The value of the first real (nonimaginary) element of the mxArray. Notice that mxGetScalar returns a double. Therefore, if real elements in the mxArray are stored as something other than doubles, mxGetScalar automatically converts the scalar value into a double. To preserve the original data representation of the scalar, you must cast the return value to the desired data type.

If array_ptr points to a structure mxArray or a cell mxArray, mxGetScalar returns 0.0.

If array_ptr points to a sparse mxArray, mxGetScalar returns the value of the first nonzero real element in the mxArray.

If array_ptr points to an empty mxArray, mxGetScalar returns an indeterminate value.

Description

Call mxGetScalar to get the value of the first real (nonimaginary) element of the mxArray.

In most cases, you call mxGetScalar when array_ptr points to an mxArray containing only one element (a scalar). However, array_ptr can point to an mxArray containing many elements. If array_ptr points to an mxArray containing multiple elements, mxGetScalar returns the value of the first real element. If array_ptr points to a two-dimensional mxArray, mxGetScalar returns the value of the (1,1) element; if array_ptr points to a three-dimensional mxArray, mxGetScalar returns the value of the (1,1,1) element; and so on.

Examples

Get the first real element of the first two input arguments to a MEX-file:

mxGetScalar does not return imaginary data. The easiest way to get an imaginary scalar is to dereference the pointer returned by mxGetPi. For example, consider the MEX-file entitled ImagScal:

Given an mxArray named b containing some imaginary elements

For additional examples, see mxgetscalar.c and mxgetscalar2.c in the mx subdirectory of the examples directory.

See Also

mxGetM, mxGetN



[ Previous | Help Desk | Next ]