Finding similar values in matrices and removing them?

1 次查看(过去 30 天)
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 个评论
Niko
Niko 2017-6-13
编辑:Niko 2017-6-13
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?

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2017-6-13
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, :);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by