Why is mxGetPi giving an Access Violation?
Mostra commenti meno recenti
The attached script - which is very stripped down - works until I un-comment line 48, which uses mxGetPi, at which point I am given an access violation. I managed to get this far by allocating memory for input vectors prior to using mxGetPr/Pi (if this isn't advisable, please let me know. But it does seem to eliminate access violation errors for mxGetPr). The variable 'volume' (the first rhs variable) can be taken as 1, while I am using a vector (length 100*volume) of zeros for the second rhs input, and a vector of length 100*volume of ones for the 3rd rhs input.
How can I prevent an access violation when using mxGetPi?
#include "mex.h"
void test_function(double *out_mat,long int volume,
double *Mx_in,double *My_in,double *Mz_in)
{
long int k;
double Mxyz[3];
for (k=0; k <= 100*volume-1; ++k)
{
Mxyz[0] = Mx_in[k];
Mxyz[1] = My_in[k];
Mxyz[2] = Mz_in[k];
out_mat[k] = Mxyz[0] + Mxyz[1] + Mxyz[2];
}
}
/*************************************************************************/
// MEX FUNCTION HERE //
/*************************************************************************/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nlhs != 1){
mexErrMsgTxt("ERROR: Number of arguments does not equal 9. \n");
}
if (nrhs != 3){
mexErrMsgTxt("ERROR: Number of RHS objects is incorrect. \n");
}
double volume;
volume = mxGetScalar(prhs[0]);
double *Mx_in;
double *My_in;
double *Mz_in;
Mx_in = mxMalloc(sizeof(double) * 100*volume);
My_in = mxMalloc(sizeof(double) * 100*volume);
Mz_in = mxMalloc(sizeof(double) * 100*volume);
Mx_in = mxGetPr(prhs[1]);
Mz_in = mxGetPr(prhs[2]);
/* My_in = mxGetPi(prhs[1]); */
double *out_mat;
plhs[0] = mxCreateDoubleMatrix(100*volume,1,mxREAL);
out_mat = mxGetPr(plhs[0]);
test_function(out_mat,volume,Mx_in,My_in,Mz_in);
}
1 Commento
James Tursa
il 24 Ago 2016
I went ahead and posted your code in your Question.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Introduction to Installation and Licensing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!