External Interfaces/API Reference |
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
See timestwoalt.c
and xtimesy.c
in the refbook
subdirectory of the examples
directory.
For additional examples, see mxsetdimensions.c
in the mx
subdirectory of the examples
directory; see mexget.c
, mexlock.c
and mexsettrapflag.c
in the mex
subdirectory of the examples
directory.
See Also
mxGetPr | mxGetString |