Generate mex code for a MATLAB function containing other mex functions (R2011a)

1 view (last 30 days)
For example, I've already generated the mex code for the following function (trying to minimize built-in MATLAB function calls, hence the custom cross product code here):
function supX = getSuperCross(v)
%#codegen
supX = [0 -v(3) v(2);
v(3) 0 -v(1);
-v(2) v(1) 0];
end
Which works fine when called as getSuperCross_mex. Now I want to generate mex code for another function which calls getSuperCross in its mex form.
Original code:
function R = getRotation(axis, angleRad)
R = eye(3) + getSuperCross(axis)*sin(angleRad) + (1 - cos(angleRad))*(axis*axis' - eye(3));
end
Attempt at mex generation:
function R = getRotation(axis, angleRad)
%#codegen
supX = coder.nullcopy(zeros(3,3));
coder.ceval('getSuperCross_mex',coder.wref(supX),axis);
R = eye(3) + supX*sin(angleRad) + (1 - cos(angleRad))*(axis*axis' - eye(3));
end
I get a few different errors trying different implementations (as I'm 100% on how this works)
If code looks as given: "Build error: Compilation returned error status code 2. See the target build log for further details." --> "...8 Writing library for getRotation_mex.mexw32, 9 Error GETROTATION.C 52 undefined reference to _getSuperCross_mex, 10 gmake: * [getRotation_mex.mexw32] Error 1"
Including a supX= before the coder.ceval call with and without the coder.wref inside: "Not a scalar location; C function calls always return scalar values." which I though would be solved by the coder.nullcopy call.
Hopefully my issue is clear here, how am I supposed to call this getSuperCross_mex so it isn't generating more code than I need? I've tried to implement coder.extrinsic with no success and have started to look into mexCallMATLAB.
Thanks in advanced for any help!

Answers (1)

Kaustubha Govind
Kaustubha Govind on 17 Aug 2012
Edited: Kaustubha Govind on 21 Aug 2012
How about just:
function R = getRotation(axis, angleRad)
coder.extrinsic('getSuperCross_mex');
temp = zeros(3,3); %expected output type of getSuperCross_mex
temp = getSuperCross_mex(axis);
R = eye(3) + temp*sin(angleRad) + (1 - cos(angleRad))*(axis*axis' - eye(3));
end
Since you're simply generating another MEX file from getRotation (and not standalone code to be run outside of MATLAB), MATLAB Coder will know to simply call back into the MATLAB Engine for getSuperCross_mex.
  3 Comments
Kaustubha Govind
Kaustubha Govind on 21 Aug 2012
Ah. It's because MATLAB Coder doesn't know what type getSuperCross_mex(axis) returns. It might be best to pre-allocate an intermediate variable to the expected type. Please see my update answer above.
Bob Dart
Bob Dart on 17 Nov 2014
What if he wanted to build a getRotation.dll file? How would he invoke his getSuperCross_mex then?
Thanks!

Sign in to comment.

Categories

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!