Azzera filtri
Azzera filtri

Finding similar values in matrices and removing them?

2 visualizzazioni (ultimi 30 giorni)
I have some matrices and want to find values that are similar in them and then create new matrices without them.
For example, if I have
one set of x1,y1 values (1,10) (2,20) (3,30) (4,40) (5,50)
second set of x2,y2 values (100,901) (200,902) (300,903) (2,904)
These values are present in different matrices( rows1, columns1) and (rows2, columns2) I want the program to automatically recognize that the x value 2 is shared between the two sets and I want it to remove the whole ordered pair of (2,20) and (2,904) from both sets. It doesn't matter if the y value is shared, only a common x value should signal it to remove the entire ordered pair from both sets.
  1 Commento
Niko
Niko il 13 Giu 2017
Modificato: Niko il 13 Giu 2017
Do you have only two matrices, or more than two? If more than two, do you want to remove a row only if the x value appears in all matrices, or do you want to remove it as long as x appears more than twice? Also, are the x values in each matrix unique?

Accedi per commentare.

Risposta accettata

Guillaume
Guillaume il 13 Giu 2017
Assuming that the x values are not repeated in each matrix, and assuming that your weird notation (please use valid matlab notation to avoid ambiguity) means that x is column1 and y is column2, then:
[~, rows1, rows2] = setxor(matrix1(:, 1), matrix2(:, 1));
matrix1 = matrix1(rows1, :);
matrix2 = matrix2(rows2, :);

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by