Matlab Coder cannot compile MEX function calls due to unknown type

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.

답변 (1개)

Ryan
Ryan 2025년 4월 7일
이동: Walter Roberson 2025년 4월 8일
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!

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

릴리스

R2024a

질문:

2025년 4월 4일

이동:

2025년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by