Check and eliminate rows based on conditions 2
1 回表示 (過去 30 日間)
古いコメントを表示
Hi. I have a matrix as below. I need help to code this problem.
A =
[1.0000 -0.1367 0.0366 0.2431 0.1541 0.2263 0.3913 -0.1903
-0.1367 1.0000 -0.3278 -0.1718 -0.3803 -0.1378 -0.0839 0.2210
0.0366 -0.3278 1.0000 0.2087 0.4730 0.2077 0.0717 -0.1989
0.2431 -0.1718 0.2087 1.0000 0.2513 0.3382 0.5135 -0.3838
0.1541 -0.3803 0.4730 0.2513 1.0000 0.1547 0.0867 -0.1398
0.2263 -0.1378 0.2077 0.3382 0.1547 1.0000 0.5096 -0.4888]
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, 5, and 6 will eliminate. End result after check and eliminate will produce matrix B as below.
A =
0.0366 -0.3278 1.0000 0.2087 0.4730 0.2077 0.0717 -0.1989
0.1541 -0.3803 0.4730 0.2513 1.0000 0.1547 0.0867 -0.1398
0.2263 -0.1378 0.2077 0.3382 0.1547 1.0000 0.5096 -0.4888
2 件のコメント
Image Analyst
2017 年 7 月 4 日
"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." <=== that is contradictory. The second sentence contradicts the first. Previous rows NEED to be less than the current row or else the third column will not monotonically increase. If you REMOVE the previous row, you are no longer guaranteed that each row will be more than the above row.
採用された回答
Andrei Bobrov
2017 年 7 月 4 日
編集済み: Andrei Bobrov
2017 年 7 月 4 日
[~,ii] = sort(A(:,3),'descend');
for MATLAB >= R2016b
out = A(ii(all(tril(ii < ii')==0,2)),:);
for MATLAB <= R2016a
out = A(ii(all(tril(bsxfun(@lt,ii(:),ii(:)'))==0,2)),:);
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!