필터 지우기
필터 지우기

remove values of a matrix from another

조회 수: 5 (최근 30일)
James
James 2014년 5월 6일
답변: José-Luis 2014년 5월 6일
Hi,
I have 2 matrices that are just lists of numbers. Matrix "A" is 380x1 and Matrix "B" is 230x1. I am trying to remove all of the numbers that are in "B" from "A". All of the numbers that are in B are in A so that should not be a problem. I have been trying to use
A(B)=[];
That is giving me the error "Index of element to remove exceeds matrix dimensions." I don't understand this since B is smaller than A.
Are there any other ways to do this?
Thanks in advance.

채택된 답변

José-Luis
José-Luis 2014년 5월 6일
A = A(~ismember(A,B))

추가 답변 (1개)

Sara
Sara 2014년 5월 6일
If A and B are 1D arrays:
for i = 1:numel(B)
A(A==B(i)) = [];
end

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by