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 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!