Matlab Coder cannot compile MEX function calls due to unknown type

8 views (last 30 days)
I am trying to use Matlab Coder to convert a moderately-sized existing sim tool to C++ to get a headstart vs re-writing it from scratch. However, I am running into an issue because my tool already uses MEX functions for coordinate transforms (all over the code), but whenever values from those functions are assigned, Coder will throw an error saying it cannot assign an unknown type to a double array. Is there any to get it to recognize that these functions are returning doubles? Worst case I guess I can just re-create the Matlab version of the transformations from scratch and go back and integrate the C++ source of the transforms later, but I would like to avoid that if possible.

Answers (1)

Ryan
Ryan on 7 Apr 2025
Moved: Walter Roberson on 8 Apr 2025
Hi William,
To allow MATLAB Coder to determine the type of an assignment to an extinsic call, you can add a preceding declaration to that variable with a value of the type you need. For example,
coder.extrinsic("myext");
x = 0; % add this declaration
x = myext(); % myext returns double
use(x);
This happens since extrinsic functions return mxArrays, which are untyped without the added declaration. For more information, visit this help page: https://www.mathworks.com/help/coder/ug/use-matlab-engine-to-execute-a-function-call-in-generated-code.html#bq1h2z9-46
Please let me know if I can help you further!

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!