Finding similar values in matrices and removing them?

조회 수: 1 (최근 30일)
awezmm
awezmm 2017년 6월 13일
답변: Guillaume 2017년 6월 13일
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