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
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
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 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by