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

2 views (last 30 days)
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.

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 12 Feb 2014
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.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!