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.

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2026년 3월 2일

1 개 추천

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 General Applications에 대해 자세히 알아보기

질문:

2026년 3월 2일

댓글:

2026년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by