How to generate code for mex files too while generating hardware specific code from simulink ?

1 回表示 (過去 30 日間)
My simulink model contains a MATLAB function block which calls a precompiled mex file. I want to generate the code from this model for a specific hardware. But when I compile the generated C code, the line calling the mex file gives an error. I want to be able to generate c code without the error. Is there a way to do this?
Thanks.

採用された回答

Kaustubha Govind
Kaustubha Govind 2014 年 2 月 12 日
Since MEX-files are specific to the MATLAB environment, you cannot run them on an embedded target. If you have the equivalent standalone C code equivalent also, you can use the following code style to call the MEX-file during simulation, and the C-code in the generated code:
function y = myfcn(u)
coder.extrinsic('mymex');
y = 0; %pre-allocate
if coder.target('Sfun')
y = mymex(u);
else
y = coder.ceval('foo', u);
end
Please refer to the documentation for more information on coder.target and coder.ceval.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by