Check and eliminate rows based on conditions.

조회 수: 2 (최근 30일)
yue ishida
yue ishida 2016년 8월 2일
댓글: yue ishida 2017년 7월 5일
Hi. I have a matrix as below. I need help to code this problem.
A=
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 0 1
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
1. Therefore, I have to check every row in third column.
2. For every row in third column, I have to ensure that all previous rows have more value than current row value. If any previous row value in third column is less than current value, that previous row will be eliminated. Else, previous row will maintain.
3. For matrix A, as result, all rows except row 3, 10, 11, 12, and 13 will eliminate. End result after check and eliminate will produce matrix B as below.
B=
0 0 1 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
Thank you.
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 8월 2일
According to your rules, rows 11, 12, and 13 should be retained. The entry in the third column for those is 0, and no previous row has a value less than 0.
yue ishida
yue ishida 2016년 8월 2일
편집: yue ishida 2016년 8월 2일
Thanks for your correction. You're right. I'm missing on row 11, 12, and 13 too. I already improved my question.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2016년 8월 2일
mask = A(:,3) == max(A(:,3));
A = A(mask,:);
  댓글 수: 5
Walter Roberson
Walter Roberson 2017년 7월 4일
Please explain your question. What are the expected results and what are the rules?
yue ishida
yue ishida 2017년 7월 5일
can we apply similar code to cell? the cell is like this. algorithm is same.
step2 =
'Q1' [1x117 char] [22] [0.8148]
'Q2' [1x86 char] [17] [0.6296]
'Q3' [1x57 char] [12] [0.4444]
'Q4' [1x86 char] [17] [0.6296]
'Q5' [1x67 char] [14] [0.5185]
'Q6' [1x113 char] [22] [0.8148]
This is algorithm needed.
1. Therefore, I have to check every row in third column.
2. For every row in third column, I have to ensure that all previous rows have more value than current row value. If any previous row value in third column is less than current value, that previous row will be eliminated. Else, previous row will maintain.
3. For cell step 2,, as result, all rows except row 1 (Q1) and last (Q6) will eliminate.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by