Check and eliminate rows based on conditions.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
yue ishida
am 2 Aug. 2016
Kommentiert: yue ishida
am 5 Jul. 2017
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 Kommentare
Walter Roberson
am 2 Aug. 2016
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.
Akzeptierte Antwort
Walter Roberson
am 2 Aug. 2016
mask = A(:,3) == max(A(:,3));
A = A(mask,:);
5 Kommentare
Walter Roberson
am 4 Jul. 2017
Please explain your question. What are the expected results and what are the rules?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!