How can I generate c code for inbuilt MATLABfunction using codegen ?

1 view (last 30 days)
codegen worked fine in simple functions I wrote. I have to generate c code forestimateGeometricTransform
1)Tried with all inputs defined | *
codegen estimateGeometricTransform -args {M1,M2,ch} -report -config:lib
*Error recieved* * _:The extrinsic function 'projective2d' is not available for standalone code generation. It must be eliminated for stand-alone code to be generated. It could not be eliminated because its outputs appear to influence the calling function. Fix this error by not using 'projective2d' or by ensuring that its outputs are unused.
Error in ==> estimateGeometricTransform Line: 174 Column: 17 Code generation failed: Open error report. Error using codegen (line 144)_ *
2)So tried to bypass code generation of projective2d by addinf a line in the inbuilt function
coder.extrinsic ('affine2d','projective2d');
*Error recieved* same as above
3)tried to eliminate line of code where ' * projective2d' * appears
%tform = projective2d(tmatrix);
Error recieved Output argument 'tform' is not assigned on some execution paths.
Error in ==> estimateGeometricTransform Line: 1 Column: 11 Code generation failed: Open error report. Error using codegen (line 144)

Accepted Answer

Andy Sonnenburg
Andy Sonnenburg on 25 Jul 2014
New versions of MATLAB Coder should support
projective2d
for code generation (R2013a and later). See projective2d for more information.
Adding
coder.extrinsic('projective2d')
will not help when compiling with
-config:lib
where the extrinsic function has a side effect - usually via an output variable. Put another way, coder.extrinsic will only help when compiling with -config:lib if the the use of the function is "dead". See coder.extrinsic for more information.
The commenting out of the line that assigns tform results in an error because tform can no longer be proven to be definitely assigned before first used. For example, changing
tform = ...
foo(tform)
to
% tform = ...
foo(tform)
will result in an error because tform will not definitely be assigned before use (and in this example, is never assigned before use).
  2 Comments
Avithal
Avithal on 27 Jul 2014
Hi Andy , It really helped me , commented the variable and generated the code . I am on the trial version of MATLAB2014a, maybe that is the problem with projective2d.
Ryan Livingston
Ryan Livingston on 28 Jul 2014
In R2014a, projective2d should be supported for code generation. Search for it here:
When something is "supported for code generation" there is generally no need to use coder.extrinsc. You should be able to just remove the:
coder.extrinsic('projective2d')
from your code.
Then you will be able to call projective2d in your code and generate code that uses its output. So:
tform = projective2d(tmatrix);
should be perfectly allowed without the coder.extrinsic call for projective2d.

Sign in to comment.

More Answers (0)

Categories

Find more on Generating Code in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!