I get this error "Too many return arguments are specified. Specify only one."
I understand what it means, but it does not make any sense. Since I have already two output blocks and scope in my simulink file.
What could be the reason for this error?
This my "error" code:
[tout,yout]=sim("TP_sub.slx")
There is no problem with your simulink model, the problem is how you call the sim
function. If you look at the docs, you see that sim
only returns one output:
simOut = sim(modelname)
In earlier versions of Matlab, it was possible to add the state and output as additional output arguments, but currently you can only output a simOut
object.
This simOut
object will contain some information, but by default it will not contain the simulation time and model outputs.
You can obtain this data by adding additional arguments to the sim
call (complete list here). For example, using the 'vdp'
model,
mdl = 'vdp';
load_system(mdl);
simOut = sim(mdl, 'SaveOutput','on','OutputSaveName','yout', 'SaveTime', 'on')
you will obtain
simOut =
Simulink.SimulationOutput:
tout: [64x1 double]
yout: [64x2 double]
SimulationMetadata: [1x1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char]
from which you can get the simulation time, output 1 and 2 by
t = simOut.tout;
y1 = simOut.yout(:,1);
y1 = simOut.yout(:,2);
Another option to get the data in your workspace is to add To Workspace blocks, like you are already doing.