Duplicating an mxArray without first storing it as a plhs?
조회 수: 1 (최근 30일)
이전 댓글 표시
I’m writing a MEX file in C where I need to duplicate an mxArray in the code. What I’m currently doing is this:
plhs[0] = mxCreateDoubleMatrix(n, p, mxREAL);
C = mxGetPr(plhs[0]);
…
…
in = mxDuplicateArray(plhs[0]);
a = mxGetPr(in);
…
I’m creating a double mxArray and storing it as the first output to Matlab: plhs[0]. I then get the pointer to it called C and perform my calculations on that. A bit later in the code I need to make a copy of C, which works great by calling mxDuplicateArray on the plhs[0].
However, I would like to do the same thing but avoid placing C as a Matlab output ( plhs).
So instead I would like to be able to do something like this:
C = mxGetPr(mxCreateDoubleMatrix(n, p, mxREAL));
…
…
in = mxDuplicateArray(C);
a = mxGetPr(in);
…
But doing that does not work and makes Matlab crash. Can anyone advise me on how I should write it instead? I’m sure there is a very trivial solution to my problem, I’m just very unfamiliar with how to use the MEX functions.
Thanks.
댓글 수: 0
채택된 답변
Philip Borghesani
2017년 1월 9일
편집: Philip Borghesani
2017년 1월 9일
You don't need to put the value into plhs but you do need to put it somewhere. You must need the array for some reason later in the code too?
mxarray* ar1
mxarray* in;
double * C;
double * a;
ar1=mxCreateDoubleMatrix(n, p, mxREAL);
in = mxDuplicateArray(ar1);
C = mxGetPr(ar1);
a = mxGetPr(in);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Troubleshooting in MATLAB Compiler SDK에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!