-
Notifications
You must be signed in to change notification settings - Fork 36
/
mexutil.c
44 lines (41 loc) · 1.16 KB
/
mexutil.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "mexutil.h"
/* Functions to create uninitialized arrays. */
mxArray *mxCreateNumericArrayE(mwSize ndim, const mwSize *dims,
mxClassID classid, mxComplexity ComplexFlag)
{
mxArray *a;
mwSize i;
mwSize *dims1 = (mwSize *)mxMalloc(ndim*sizeof(mwSize));
mwSize sz = 1;
for(i=0;i<ndim;i++) {
sz *= dims[i];
dims1[i] = 1;
}
a = mxCreateNumericArray(ndim,dims1,classid,ComplexFlag);
sz *= mxGetElementSize(a);
mxSetDimensions(a, dims, ndim);
mxFree(dims1);
mxSetData(a, mxRealloc(mxGetData(a), sz));
if(ComplexFlag == mxCOMPLEX) {
mxSetPi(a, (double*)mxRealloc(mxGetPi(a),sz));
}
return a;
}
mxArray *mxCreateNumericMatrixE(mwSize m, mwSize n, mxClassID classid,
mxComplexity ComplexFlag)
{
mwSize sz = m*n*sizeof(double);
mxArray *a = mxCreateNumericMatrix(1, 1, classid, ComplexFlag);
mxSetM(a,m);
mxSetN(a,n);
mxSetPr(a, (double*)mxRealloc(mxGetPr(a),sz));
if(ComplexFlag == mxCOMPLEX) {
mxSetPi(a, (double*)mxRealloc(mxGetPi(a),sz));
}
return a;
}
mxArray *mxCreateDoubleMatrixE(mwSize m, mwSize n,
mxComplexity ComplexFlag)
{
return mxCreateNumericMatrixE(m,n,mxDOUBLE_CLASS,ComplexFlag);
}