Omar Faig
Omar Faig

Reputation: 13

Error "Too many return arguments are specified. Specify only one."

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.

enter image description here

What could be the reason for this error?

This my "error" code:

[tout,yout]=sim("TP_sub.slx") 

Upvotes: 1

Views: 1611

Answers (3)

Omar Faig
Omar Faig

Reputation: 13

Thanks for your Comments . But actually it si possible to get multiple outputs from sim function . You just shoulld change" Model Confugiration Settings > Data Import/Export pane and UNCHECK Single simulation"

Upvotes: 0

Martin Rosenau
Martin Rosenau

Reputation: 18493

I understand what it means, but it does not make any sense.

What could be the reason for this error?

Obviously you are not aware that a and b in the following example may be something completely different:

[x,y] = myFunction(someValue)
a = [x,y]

b = myFunction(someValue)

At least if the function myFunction is a "mex function" (and most Simulink-related functions are!), the function myFunction can be defined in a way that totally different values are returned depending on the number of return values given:

[x,y]=myFunction(someValue) may return two 10x20 matrices and b=myFunction(someValue) may return a single number (1x1 matrix).

You cannot just use [x,y]=someFunction(someValue) to "split" a single value returned by the function someFunction into two parts!

The sim function returns one single value.

Upvotes: 0

rinkert
rinkert

Reputation: 6863

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.

Upvotes: 1

Related Questions