101 #define mwSignedIndex int
107 #define VariableType_Temporary 4
180 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
184 mwSize *dims_old, *dims_new;
192 mexErrMsgTxt(
"Too many input arguments.");
195 mexErrMsgTxt(
"Not enough input arguments.");
198 mexErrMsgTxt(
"Too many output arguments.");
200 if( mxIsSparse(prhs[0]) || (!mxIsNumeric(prhs[0]) && !mxIsChar(prhs[0]) && !mxIsLogical(prhs[0])) ) {
201 mexErrMsgTxt(
"The first input argument must be a full numeric value, or char, or logical.");
203 if( !mxIsChar(prhs[1]) ) {
204 mexErrMsgTxt(
"The second input argument must be a character array.");
209 inbytes = mxGetElementSize(prhs[0]);
213 outstring = mxArrayToString(prhs[1]);
216 if( strcmp(outstring,
"int8") == 0 ) {
217 outclass = mxINT8_CLASS;
219 }
else if( strcmp(outstring,
"uint8") == 0 ) {
220 outclass = mxUINT8_CLASS;
222 }
else if( strcmp(outstring,
"int16") == 0 ) {
223 outclass = mxINT16_CLASS;
225 }
else if( strcmp(outstring,
"uint16") == 0 ) {
226 outclass = mxUINT16_CLASS;
228 }
else if( strcmp(outstring,
"int32") == 0 ) {
229 outclass = mxINT32_CLASS;
231 }
else if( strcmp(outstring,
"uint32") == 0 ) {
232 outclass = mxUINT32_CLASS;
234 }
else if( strcmp(outstring,
"int64") == 0 ) {
235 outclass = mxINT64_CLASS;
237 }
else if( strcmp(outstring,
"uint64") == 0 ) {
238 outclass = mxUINT64_CLASS;
240 }
else if( strcmp(outstring,
"double") == 0 ) {
241 outclass = mxDOUBLE_CLASS;
243 }
else if( strcmp(outstring,
"single") == 0 ) {
244 outclass = mxSINGLE_CLASS;
246 }
else if( strcmp(outstring,
"char") == 0 ) {
247 outclass = mxCHAR_CLASS;
250 }
else if( strcmp(outstring,
"logical") == 0 ) {
251 outclass = mxLOGICAL_CLASS;
256 mexErrMsgTxt(
"Unsupported class.\n");
262 if( mxIsComplex(prhs[0]) && !out_numeric ) {
263 mexErrMsgTxt(
"Cannot typecast a complex input to a non-numeric class.\n");
268 if( mxIsEmpty(prhs[0]) ) {
270 plhs[0] = mxCreateNumericArray(mxGetNumberOfDimensions(prhs[0]),
271 mxGetDimensions(prhs[0]),
273 }
else if( outclass == mxCHAR_CLASS ) {
274 plhs[0] = mxCreateCharArray(mxGetNumberOfDimensions(prhs[0]),
275 mxGetDimensions(prhs[0]));
277 plhs[0] = mxCreateLogicalArray(mxGetNumberOfDimensions(prhs[0]),
278 mxGetDimensions(prhs[0]));
285 ndim = mxGetNumberOfDimensions(prhs[0]);
286 dims_old = mxGetDimensions(prhs[0]);
287 for( i=0; i<
ndim; i++ ) {
288 if( dims_old[i] != 1 || i == ndim-1 ) {
289 k = (dims_old[i] * inbytes) / outbytes;
290 if( k * outbytes != dims_old[i] * inbytes ) {
291 mexErrMsgTxt(
"Too few input values to make output type.\n");
297 dims_new = mxMalloc(ndim *
sizeof(*dims_new));
298 for( i=0; i<
ndim; i++ ) {
299 dims_new[i] = dims_old[i];
313 mxSetDimensions(plhs[0],dims_new,ndim);
318 if( outclass == mxDOUBLE_CLASS ) {
319 if( mxGetNumberOfElements(plhs[0]) == 1 ) {
324 }
else if( out_numeric ) {
union mxArray_Tag::@1 irClassNameID
union mxArray_Tag::@2 jcClassID
union mxArray_Tag::@0 Mdims
#define VariableType_Temporary
mxArray * mxCreateSharedDataCopy(const mxArray *mx)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])