mxGetScalar (C and Fortran)
Real component of first data element in array
C Syntax
#include "matrix.h" double mxGetScalar(const mxArray *pm);
Fortran Syntax
#include "fintrf.h" real*8 mxGetScalar(pm) mwPointer pm
Arguments
pmPointer to an
mxArray; cannot be a cellmxArray, a structuremxArray, or an emptymxArray.
Returns
The value of the first real (nonimaginary) element of the
mxArray.
In C, mxGetScalar returns a double. If real
elements in the mxArray are of a type other than
double, then mxGetScalar automatically
converts the scalar value into a double. To preserve the original
data representation of the scalar, cast the return value to the desired data
type.
If pm points to a sparse mxArray, then
mxGetScalar returns the value of the first nonzero real element
in the mxArray. If there are no nonzero elements, then the function
returns 0.
Description
Call mxGetScalar to get the value of the first real
(nonimaginary) element of the mxArray.
Usually you call mxGetScalar when pm points to
an mxArray containing only one element (a scalar). However,
pm can point to an mxArray containing many
elements. If pm points to an mxArray containing
multiple elements, then the function returns the value of the first real element. For
example, if pm points to a two-dimensional
mxArray, then mxGetScalar returns the value of
the (1,1) element. If pm points to a
three-dimensional mxArray, then the function returns the value of the
(1,1,1) element; and so on.
Use mxGetScalar on a nonempty mxArray of type
numeric, logical, or char only. To test for these conditions, use Matrix Library
functions such as mxIsEmpty, mxIsLogical,
mxIsNumeric, or mxIsChar.
If the input value to mxGetScalar is type
int64 or uint64, then the value might lose
precision if it is greater than flintmax.
Examples
To open an example, type:
edit([fullfile(matlabroot,"extern","examples","refbook","filename")]);
where filename is:
To open an example, type:
edit([fullfile(matlabroot,"extern","examples","mex","filename")]);
where filename is:
To open an example, type:
edit([fullfile(matlabroot,"extern","examples","mx","filename")]);
where filename is: