Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Mex-File issue : correlated gaussians

2 visualizaciones (últimos 30 días)
Brian
Brian el 17 de Ag. de 2014
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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.

Respuestas (1)

Jan
Jan el 11 de Mzo. de 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?

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by