Measure time difference peaks and stores it
Show older comments
Hi,
Can anyone help me with a code to measure the time difference from the moment the peak is 1 till it goes back to zero and then stores it. Then it repeats again for the next peak and the next till it goes over all the peaks. So for example the graph below shows the first peak occurs at around 15197 seconds and ends at 15562 seconds, hence time difference is 365s which is then stored in a matrix. Then the code continues to the next peak and measures that time then stores it. It keeps doing that until it stores all those times.
find peak doesn't work well for my data to use widths and all that. I need some type of for and if loop. Any help appreciated

Accepted Answer
More Answers (2)
David Hill
on 17 Aug 2022
I assume you have an t-array and a y-array.
c=1;
while any(y>=1)
f1=find(y>=1,1);
y(1:f1-1)=[];
f2=find(y<=0,1);
y(1:f2-1)=[];
deltaT(c)=t(f2)-t(f1);%provides an array of the peak time periods
t(1:f2-1)=[];
c=c+1;
end
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

