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 CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by