c - How to check if variable is Scalar or Array before mxIsScalar was introduced? -
in matlab's mex files there function mxisscalar
tells if input mex files scalar or not. function has been introduced in r2015a.
if using previous version of matlab (2014b in case, if matters), elegant way of checking if input scalar or array?
do need combine mxgetnumberofdimensions
, mxgetdimensions
, mxisnumeric
it? or there other clear , simple way of doing it? favor readability on speed.
mrows = mxgetm(prhs[0]); ncols = mxgetn(prhs[0]); if (mrows==1 && ncols==1) { // scalar prhs[0] here }
note that, if prhs[0] has more 2 dimensions n, mxgetn result of product of dimensions 2 ... n. mxgetm return first dimension. may not check sparse matrices these may not return actual number of elements in matrix.
a full example mex file can found @ http://www.mathworks.com/help/matlab/matlab_external/passing-a-scalar_btgcjh1-1.html.
Comments
Post a Comment