matlab coder generation mex verification failed?

1 view (last 30 days)
When I use matlab coder app to generate C code from my matlab code, I first start to verify if mex is runnable, but this step directly reported an error failure, according to the prompt I do not know how to modify, I am sure edgeIJ(:,1) is a single non-empty column vector of length at least 2, the matlab code runs without problems, please ask how to modify Thanks!
See attachment for additional code

Accepted Answer

Matan Silver
Matan Silver on 14 Apr 2022
I believe we can see the problem if we run myFun normally in MATLAB and set a breakpoint on line 88. We will see that the output of the call to mink is:
K>> [aa,bb]=mink(edgeIJ(:,1),2)
aa =
bb =
however, idxs, which is receiving the second output of mink, is 1x2, not 2x1:
K>> idxs
idxs =
3 4
So in this case, MATLAB Coder is complaining about assigning a 2x1 value into a 1x2 variable. You could perhaps fix this by storing the second output in an intermediate variable, and assigning it to idxs after transposing:
[minRows,idxs_untransposed] = mink(edgeIJ(:,1),2);
When I run "check for issues" on your example after making this change, "check for issues" passes. However, I'm not sure if this is actually what you want to do in your algorithm, so please check to make sure it is doing the right thing.

More Answers (0)


Find more on MATLAB Coder in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!