~ismember does not work on my matrix

조회 수: 1 (최근 30일)
RDG
RDG 2013년 9월 11일
A=[1 1 5 6;
2 2 1 5;
3 1 4 2;
4 4 2 1;
5 6 2 1;]
B=[1 1 1; %remain
1 4 2;
1 5 6;
2 1 5;
4 2 1;
4 2 2; %remain
6 2 1;
6 3 1;] %remain
I would like the output, C to display
C=[1 1 1;
4 2 2;
6 3 1;]
I tried the following:
[idx1,idx2] = ismember(A(:,2:4),B,'rows');
However, when I used ~
[idx1,idx2] = ~ismember(A(:,2:4),B,'rows');
An error's returned.
May I know why is this so and any suggestions on how to get around this?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 9월 11일
Try
C = setdiff(B,A(:,2:end),'rows')
or
C = B(~ismember(B,A(:,2:end),'rows'),:)
  댓글 수: 1
RDG
RDG 2013년 9월 11일
Both works! Thanks. Will understand it for myself.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by