How to iterate over multiple outputs in a function
Ältere Kommentare anzeigen
I have a model contained in a Simulink "Matlab Function" block that contains code which looks like this:
function [output1, output2, output3, output4, etc...] = func(input)
How do I iterate over and update the outputs?
If I just assign individually, ie: output1 = 1, I can see that the value was updated as expected.
However, if I create an array and assign all outputs, like this:
outputs = [output1, output2, output3, ouput4, etc...];
Then do: outputs(1) = 1;
I do not see the matlab function block output at output1 update to 1.
How can I successfully loop over and update multiple outputs to a function contained inside this Matlab function block?
Antworten (1)
Sulaymon Eshkabilov
am 28 Jun. 2023
If understood your question correctly, here is one very simple example how to get it:
INS = randi(25, 1,5); % Randomly generated 5 input values
for ii=1:numel(INS)
IN = INS(ii); % One input per cycle
OUT{ii} = sim("Multiple_OUT.slx") % Recall Simulink model and simulate it per cycle. And keep the sim results in OUT
end
Note that MATLAB fcn has this syntax to give three outputs:
function [y1, y2, y3] = fcn(u)
y1 = u;
y2 = 2*u;
y3 = u^2;
Kategorien
Mehr zu Simulink Functions finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!