| MATLAB® | ![]() |
Get real component of first data element in mxArray
#include "matrix.h" double mxGetScalar(const mxArray *pm);
real*8 mxGetScalar(pm) mwPointer pm
Pointer to an mxArray; cannot be a cell mxArray, a structure mxArray, or an empty mxArray.
The value of the first real (nonimaginary) element of the mxArray. Notice that in C, mxGetScalar returns a double. Therefore, if real elements in the mxArray are stored as something other than double, 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.
mxGetScalar should only be called when pm points to a nonempty numeric, logical, or char mxArray. Use mx functions such as mxIsEmpty, mxIsLogical, mxIsNumeric, or mxIsChar to test for this condition before calling mxGetScalar.
If pm points to a sparse mxArray, mxGetScalar returns the value of the first nonzero real element in the mxArray.
Call mxGetScalar to get the value of the first real (nonimaginary) element of the mxArray.
In most cases, 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, mxGetScalar returns the value of the first real element. If pm points to a two-dimensional mxArray, mxGetScalar returns the value of the (1,1) element; if pm points to a three-dimensional mxArray, mxGetScalar returns the value of the (1,1,1) element; and so on.
See timestwoalt.c and xtimesy.c in the refbook subdirectory of the examples directory.
Additional examples:
mxsetdimensions.c in the mx subdirectory of the examples directory
mexlock.c and mexsettrapflag.c in the mex subdirectory of the examples directory
![]() | mxGetProperty (C and Fortran) | mxGetString (C and Fortran) | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |