| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
#include "matrix.h" double mxGetScalar(const mxArray *pm);
real*8 mxGetScalar(pm) mwPointer pm
Pointer to 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, 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, mxGetScalar returns the value of the first nonzero real element in the mxArray. If there are no nonzero elements, mxGetScalar returns 0.
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. For example, 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.
Use mxGetScalar only on a 32-bit, nonempty, numeric, logical, or char mxArray. Use mx functions such as mxIsEmpty, mxIsLogical, mxIsNumeric, or mxIsChar to test for this condition before calling mxGetScalar.
timestwoalt.c and xtimesy.c in the matlabroot/extern/examples/refbook folder
mxsetdimensions.c in the matlabroot/extern/examples/mx folder
mexlock.c and mexsettrapflag.c in the matlabroot/extern/examples/mex folder
![]() | mxGetProperty (C and Fortran) | mxGetString (C and Fortran) | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |