codegen error diff(a)~=0
조회 수: 3 (최근 30일)
이전 댓글 표시
I use codegen to generate C code from Matlab code. in the Matlab function, I have a line of code:
a=quantile(double(reshape(z,numel(z),1)), [r 1-r]);
if diff(a) ~= 0
...
I get the error message underlining diff(a): Expected either a logical, char, int, fi, single, or double. Found an mxArray. MxArrays are returned from calls to the MATLAB interpreter and are not supported inside expressions. They may only be used on the right-hand side of assignments and as arguments to extrinsic functions.
Not sure what that means and how to fix. could anyone help me? Thanks!
댓글 수: 0
답변 (2개)
James Tursa
2016년 10월 28일
편집: James Tursa
2016년 10월 28일
mxArray variables are variables returned from extrinsic functions. There are limitations to what you can do with these variables. See this link for more info:
https://www.mathworks.com/help/coder/ug/calling-matlab-functions.html?searchHighlight=working%20with%20mxarrays
Try defining a variable first with known size and class. E.g.,
d = 0; % <-- tell the Coder expected result is a scalar double
d = diff(a);
if( d ~= 0 )
:
Also, are you sure you have the 2nd argument to quantile correct? The description says the 2nd argument should be "cumulative probability values", but it looks like you have the absolute probabilities, not the cumulative probabilities.
댓글 수: 0
Walter Roberson
2016년 10월 29일
I would recommend that you get around the problem by using
if a(1) ~= a(2)
which is the same as
diff(a(1:2)) ~= 0
but does not require calling an external function and does not lead to questions about "but suppose the quantile() returns a vector of length other than 2 so that the diff() is not going to give a scalar result?"
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!