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

조회 수: 2 (최근 30일)
Alex
Alex 2012년 8월 17일
댓글: Bob Dart 2014년 11월 17일
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!

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2012년 8월 17일
편집: Kaustubha Govind 2012년 8월 21일
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
Kaustubha Govind
Kaustubha Govind 2012년 8월 21일
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 2014년 11월 17일
What if he wanted to build a getRotation.dll file? How would he invoke his getSuperCross_mex then?
Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by