フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Mex-File issue : correlated gaussians

2 ビュー (過去 30 日間)
Brian
Brian 2014 年 8 月 17 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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.

回答 (1 件)

Jan
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?

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by