What do these steps do?

1 visualizzazione (ultimi 30 giorni)
Vineet Patel
Vineet Patel il 2 Dic 2018
Risposto: Walter Roberson il 2 Dic 2018
Hi All,
Can someone tell me what these steps mean/do? And if theres a way of simplifing the code.
xmax = [];
[t,x] = ode45(f,tspan,x0);
n = find(t>60);
x = x(n,:);
n = length(x(:,1));
k = 1;
k = k+1;
j = 1;
for i=2 : n-1
if (x(i-1,1)) < x(i,1) && x(i,1) > (x(i+1,1))
xmax(k,j)=x(i,1);
j=j+1;
end
end
Any help would be great,
Thank you

Risposta accettata

Walter Roberson
Walter Roberson il 2 Dic 2018
Run an ode45 over tspan. Some but not all of the timesteps correspond to times greater than 60; extract the ode values that were generated for those times.
That done, look for local peaks in the first column.
There are other ways to look for peaks, including vectorized ways. findpeaks() is more flexible about what a peak looks like.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by