Check and eliminate rows based on conditions 2

3 visualizzazioni (ultimi 30 giorni)
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 Commenti
Image Analyst
Image Analyst il 4 Lug 2017
"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.
yue ishida
yue ishida il 4 Lug 2017
actually, that's the point of this algorithm...

Accedi per commentare.

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 4 Lug 2017
Modificato: Andrei Bobrov il 4 Lug 2017
[~,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)),:);

Più risposte (0)

Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by