Trimming rows based on values in one column

3 ビュー (過去 30 日間)
Muneer
Muneer 2014 年 2 月 10 日
コメント済み: dpb 2014 年 2 月 10 日
Hello,
Suppose I have two columns in a matrix that look like this:
5 0
5 0
5 1
5 1
5 1
6 1
7 0
8 0
9 0
9 0
1 1
3 1
2 1
4 1
44 1
5 0
4 1
3 1
6 0
I'd like to isolate the regions that are bounded by 0s. My second column is a switch (0 off and 1 being on). And I'd only like to look at the data where the switch is on. However, I can't just delete all rows with 0 in them because I need to know the start time and end time of each instance of the switch being on. Thus, I need a zero to be at the beginning and end of each instance. Another column in this matrix is the time stamp which I will be using in another step.
Would appreciate any help or being pointed in the right direction.
Thanks in advance.
  1 件のコメント
dpb
dpb 2014 年 2 月 10 日
Use diff() on the second column to find the +/-1 locations. I'll leave you to imagine what that tells you... :)

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

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 10 日
A=[5 0
5 0
5 1
5 1
5 1
6 1
7 0
8 0
9 0
9 0
1 1
3 1
2 1
4 1
44 1
5 0
4 1
3 1
6 0]
c2=A(:,2)'
idx1=strfind(c2,[0 1])
idx2=strfind(c2,[1 0])

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by