0
votes

I have created a simple Simulink Model which adds two signals: Simulink Model

The code to control this model is the following:

clear X Y Result

data=ones(1,5);
X=timeseries(data);
Y=timeseries(data);

output = sim('model_test','StopTime',stop_time);
Result = output.get('Res');

Obviously, I wish to get the following result, a matrix containing [2 2 2 2 2]. However, my result looks like this: Simulink Result

Result is a 1x1x27 double and not a 1x5 double as hoped for. Do you know what I have to change? Is my code wrong or do I have to change settings in the simulink model? Thank you in advance!

1

1 Answers

4
votes

The problem is with how you are constructing your input data.

The syntax you are using for timeseries constructs X and Y such that they have the scalar value of 2 at time equal to 0,1,2,3 and 4 seconds. You can see this by looking at X.Time and X.Data.

From what you are expecting it looks like you are wanting to define them as being 5 element vectors at each time step. This would involve using

>> X = timeseries(ones(1,5),0);

or something similar depending on how many time points you want to define. The above defines the data only at time = 0 seconds. Again, look at the variable in the MATLAB Workspace to confirm this. (Of course if you intent having the same value at every time step then you should just use a Constant block not a From Workspace block.)

The output (as with the input) is displayed as a 3D matrix because the third dimension is time. For every simulation time step that your model takes you will have a signal value. In your model it is a scalar, but in general it will/can be any 2D matrix. You get a 1x1x27 result because your signals are scalar (the 1x1 bit) and 27 time steps are taken (the x27 bit).