Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Mex-File issue : correlated gaussians

2 vues (au cours des 30 derniers jours)
Brian
Brian le 17 Août 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello, I wrote the following code in a MexFunction:
void Gaussians(double *H, int N, double *W)
{
/* computes the matrix multiplication H*R where H is a (N x N) matrix
* and R is a (N x 1) gaussian vector */
mxArray *rhs1[2], *rhs2[2], *lhs1[1], *lhs2[1];
rhs1[0] = mxCreateDoubleScalar(N);
rhs1[1] = mxCreateDoubleScalar(1);
/* generates R = randn(N, 1) */
mexCallMATLAB(1, lhs1, 2, rhs1, "randn");
rhs2[0] = mxGetPr(H);
rhs2[1] = lhs1[0];
W = mxGetPr(lhs2[0]);
/* computes H*R */
mexCallMATLAB(1, lhs2, 2, rhs2, "mtimes");
}
There is no problem with the mex compilation but when I run the program, I get an "Acces violation" error and matlab crashes. I was not able to find where the problem comes from.
Thank you for your help
PS : I'm starting with C language and Mex-Files.

Réponses (1)

Jan
Jan le 11 Mar 2016
rhs2[0] = mxGetPr(H);
On the left side you have pointer to an mxArray, on the right you try to get the pointer to the double data of an myArray, but the argument is a pointer to a double already. It is surprising that the compiler accepts this. The next line contains similar problems:
rhs2[1] = lhs1[0];
What do you want to achieve?

Cette question est clôturée.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by