|
Hi, I have a large program written in c++ that I have been writing a MEX function for, to interface with matlab. I am passing both vectors and single values from Matlab. My c++ program will return two arrays of data to Matlab, with lengths depending on an input parameter. When I call my function from Matlab, It will run and return the first value in both of the output arrays, and then crashes Matlab, and I am even unable to reopen matlab afterwards without a restart. My code looks like this:
mexFunction(...,...){
m = mxGetM(no_of_carriers_in);
n = mxGetN(no_of_carriers_in);
// /* Assign pointers to the various parameters */
/* Ouputs*/
/* Create a matrix for the return argument */
data1_mat_out = mxCreateDoubleMatrix( (mwSize)m, (mwSize)n, mxREAL);
data1_out_ptr = mxGetPr(data1_mat_out);
len6=mxGetM(data1_mat_out);
vector<double> data1_out_data(data1_out_ptr,(data1_out_ptr+len6));
/* Create a matrix for the return argument */
data2_mat_out = mxCreateDoubleMatrix( (mwSize)m, (mwSize)n, mxREAL);
data2_out_ptr = mxGetPr(data2_mat_out);
len7=mxGetM(data2_mat_out);
vector<double> data2_out_data(data2_out_ptr,(data2_out_ptr+len7));
/*inputs*/
double *beta_ptr = (double *)mxGetData(beta_in);
len2=mxGetM(beta_in);
vector<double> beta_data(beta_ptr,(beta_ptr+len2));
int *a_ptr =(int *)mxGetData(prhs[0]);
double data5=*a_ptr;
int a_data=data5;
foo(a_data,beta_data,data1_data_out,data2_data_out);
}
//c++ code
foo(a_data, beta,vector<double> &data1_out, vector<double>&data2_out){
.....
....
....
}
With the same three lines used for a_data and beta, repeated for 5 other different variables and vectors.
Those three lines are supposed to recast the data coming from matlab to an integer or whatever type I need it to even if it comes as a double.
|