Run ANY matlab Function.m from simulink simulation

1 view (last 30 days)
I have a function written in Matlab and I want to run it from Simulink. The problem is that the MATLAB Function block in Simulink doesn't allow size changing arrays (which I have in the code), and when using matlab prescribed functions like "length", or "perms" (with the coder.extrinsic), the result is a mxArray which cannot be used for "while", etc.
I would like to know how can I run from Simulink ANY!!! Matlab function that runs perfectly in Matlab. (I tried using S-Function, but after many hours I could'nt really understand how does it works)
Thanks in advance

Accepted Answer

Mike Hosea
Mike Hosea on 4 Aug 2015
If you just want to run it from Simulink, just call your function as extrinsic. For example if your function is called myfun(a,b,c), and if myfun(a,b,c) returns, say, a 3-by-1 int32 vector, then your MATLAB function block would look something like
function y = fcn(a,b,c)
y = zeros(3,1,'int32'); % Define the output type of the myfun call.
y = myfun(a,b,c);
Just put your function in the same directory as the model or somewhere on the path.

Sign in to comment.

More Answers (0)


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!