Finding Time Intervals with corresponding data

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 件のコメント

dpb
dpb 2015 年 6 月 8 日
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.
RobB
RobB 2015 年 6 月 8 日
To make it more clear...1 means the switch is on, 0 means the switch is off. For the time values, I have exact values, but the sample rate can range between .8 seconds and 1.2 seconds, so not exactly every 1 second. Does that help at all? If I could find the beginning value and ending value of each time interval the switch is on (value of 1) I could just find the difference.

サインインしてコメントする。

 採用された回答

dpb
dpb 2015 年 6 月 8 日

1 投票

_"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 件のコメント

RobB
RobB 2015 年 6 月 8 日
編集済み: RobB 2015 年 6 月 8 日
When I use what you've suggested I get the error:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
For s, I am using VariableName(:,2) since the 1's and 0's are in the second column of the specific variable I'm looking at.
Star Strider
Star Strider 2015 年 6 月 8 日
I’m responding here rather than to your Comment to my previous Answer.
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).
dpb
dpb 2015 年 6 月 8 日
Ah, yeah, I probably should've presumed it would be a column...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2015 年 6 月 8 日

コメント済み:

dpb
2015 年 6 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by