MATLAB: Insert new mexPrintf to stop Matlab crash

crashmexmexprintf

Hello,
I'm encountering a very weird situation. My Matlab program crashed when I tried to run the mexw64 file and after modifier the c code by adding a mexPrintf("ok") line at the beginning and at the end, the program works. What could happen to my code?

Best Answer

#if !defined(_WIN32)
#define dgemm dgemm_
#endif
#include "mex.h"
#include "geometryMatrix64.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *arrayLat, *arrayLong, *arraySeax, *arrayGm, *arrayTime, *arrayIncl, *arrayPeri;
double *A, *B, *C, *D, *E, *R1, *R3, *R_L, *v, *r; /* pointers to input & output matrices*/
double t_S, raan, anom;
int ind_s, ind_s_vis;
int i, j, outputRowLen, outputColLen;
size_t m,n,p,q; /* matrix dimensions */
/* form of op(A) & op(B) to use in matrix multiplication */
char *chn = "N";
/* scalar values to use in dgemm */
double one = 1.0, zero = 0.0;
arrayLat = mxGetPr(prhs[0]);
arrayLong = mxGetPr(prhs[1]);
arraySeax = mxGetPr(prhs[2]);
arrayGm = mxGetPr(prhs[3]);
arrayTime = mxGetPr(prhs[4]);
arrayIncl = mxGetPr(prhs[5]);
arrayPeri = mxGetPr(prhs[6]);
plhs[0] = mxCreateDoubleMatrix(m, n, mxREAL);
C = mxGetPr(plhs[0]);
for (i=0;i<outputRowLen;i++){
for(j=0; j<outputColLen; j++){
C[i*outputRowLen+j] = 0;
}
}
This is a very simple code with many entrees and Matlab returned me this
Error using geometryMatrix64
Out of memory. Type HELP MEMORY for your options.
Isn't that weird while all entrees are either scalar or 3by3 matrix? What could have happened ?