codegen error diff(a)~=0
3 views (last 30 days)
Show older comments
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 Comments
Answers (2)
James Tursa
on 28 Oct 2016
Edited: James Tursa
on 28 Oct 2016
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 Comments
Walter Roberson
on 29 Oct 2016
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!