Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Mex-File issue : correlated gaussians
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
Jan
2016년 3월 11일
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?
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!