What do these steps do?

1 view (last 30 days)
Vineet Patel
Vineet Patel on 2 Dec 2018
Answered: Walter Roberson on 2 Dec 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

Accepted Answer

Walter Roberson
Walter Roberson on 2 Dec 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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!