ginni - 2021-09-11T13:44:02+00:00
Question: Can I have more than 1 output argument from a function that I use in the MATLAB Function block in Simulink?
Can I have more than 1 output argument from a function that I use in the MATLAB Function block in Simulink? I have a user written function that has multiple input and output arguments. For example: [a,b,c,d] = my_function(x,y,z) But when I try to use this in the MATLAB FCN block in Simulink I get the following error: ??? Error using ==> sim Error in MATLAB Function block 'my_model/MATLAB Fcn' while computing the output. The width of the result was 1 when a width of 4 was expected. I have specified the number of outputs from the block as 4. But only one output from the function is seen.
Expert Answer
John Williams answered .
2025-11-20
I believe the link might be complicated for some people so I will suggest a simple solution from the R2021a version that I used to save people some time.
- On the MATLAB FCN block, if you hover over to the edges that input and outputs are located in, u can see a plus indicator. Once you click and hit enter, you can easily add inputs and outpus to the amount you desire.
- If you double click the block you can copy and paste your script to use in the SIMULINK model,
I am not that experienced in SIMULINK so if a more automated way is requiered, than you might find salvation in reading through the link above.
Not satisfied with the answer ?? ASK NOW