MATLAB Answers

MATLAB function block error in Simulink

6 views (last 30 days)
I am trying to run a function in Simulink model. I have the function working without any error if I call it in an m-script. However, if I add the same function in MATLAB function block, I have dimension errors.
Why don't I see these errors when I call it in m-script? Is there is a way to debug this?


Sign in to comment.

Accepted Answer

Abdolkarim Mohammadi-Balani
Edited: Abdolkarim Mohammadi-Balani on 24 Sep 2020
Unlike m-file functions, MATLAB function block does not apply automatic array expansion. The simplest way to overcome is to define your m-file function as an extrinsic function in the MATLAB function block.
function v = fcn (u) % MATLAB function block
coder.extrinsic ('MATLAB function name'); % m-file function


Show 3 older comments
Abdolkarim Mohammadi-Balani
Create a Constant block and enter that variable's name in the Value field. Connect the Constant block to the input of the function block. If you need multiple inputs, you first define them in the function header. Then the appropriate input ports will appear on the block.
function v = fcn (u1, u2, u3) % MATLAB function block
Rubeena Parveez
Rubeena Parveez on 24 Sep 2020
Thank you, this works but I read that coder.extrinsic does not support code generation. Is there any other way to do this?
Abdolkarim Mohammadi-Balani
As far as I know, there is no way. As emphasized by documentation and the top contributor of this forum.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!