Can I have more than 1 output argument from a function that I use in the MATLAB Function block in Simulink?

33 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 27 Jun. 2009
You cannot pass more than one (1) argument out of a function that is used in the MATLAB FCN block.
If you need to pass more than one variable out of a function, you will have to concatenate all variables into one vector, and pass that vector out of the function. In other words, the single output from the function will have to be a vector with all the values that you need passed out. You can then use a Demux Block to split the vector into its individual signals.
Alternatively, you may use the Embedded MATLAB Function block. This block can accept multiple inputs and return multiple outputs.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by