Scope in SIMULINK doesn't match plot in MATLAB

Hi. I'm doing a simulation where I have a population of cells that decrease with a growth rate of -0.1 (r*p(t)). I have to simulate it in both MATLAB and SIMULINK.
The thing is, the plot in MATLAB matches the scope in SIMULINK. But when I try to simulate the model using the sim function in MATLAB, it isn't the same figure as the scope. The simulation time is different.
This is the plot using only MATLAB.
This is the scope in Simulink.
This is the plot using sim() in Matlab. I tried to use the StopTime parameter, but it doesn't stop at 100 like I want. It goes on until 434.
To simulate the model in Matlab, I used ode45.
r = -0.1;
P0 = 1000;
tsim = 100;
f1=@(t,p) r*p;
[t,p_2] = ode45(f1,[1 tsim],[P0]);
This is my model in Simulink:
And this is how I used the sim function in Matlab:
out = sim('myModel', 'StopTime', '100')
plot(out.salida1)
I think I'm not using well the StopTime parameter, but I can't find any other alternative that works for me.
Also, max(out.tout)=100.
Thank you.

 Accepted Answer

434 is the number of data points, not 434 seconds.
run
plot(out.tout, out.salida1)

More Answers (0)

Asked:

about 17 hours ago

Commented:

about 16 hours ago

Community Treasure Hunt

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

Start Hunting!