Finding Time Intervals with corresponding data
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a set of data vs. time. For simplicity, let's say at I have data recorded anywhere between once per second and 4 or 5 times per second, and each time has a corresponding value of either 1, or 0. I discard all of the entries with a value 0. How can I easily tell how much time has passed with a value of 1, and what the intervals of the time is where the corresponding value is 1. Thank you.
2 Commenti
dpb
il 8 Giu 2015
Well, unless there's something unsaid, you can't. All you've told us is there's some indicator variable but nothing about what that might indicate (if anything) re: actual clock time and you've implied that the sample rate isn't fixed hence just how many intervals it's been between is also no actual information.
Risposta accettata
dpb
il 8 Giu 2015
_"1 means the switch is on, 0 means the switch is off. ... If I could find the beginning value and ending value of each time interval the switch is on..."
istart=find([0 diff(s)]==1); % Switch 'on' from 'off' locations
iend=find([0 diff(s)]==-1); % Switch 'off' from 'on'
s is you switch indicator variable; use whatever variable/column you have for it...
3 Commenti
Star Strider
il 8 Giu 2015
That’s because dpb assumes your vector is a row vector. For your column vector, change the vector in the find argument to:
[0; diff(s)]
Note the semicolon (;). It will do a vertical concatenation rather than a horizontal concatenation (that uses either a comma (,) or a space delimiter).
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!