필터 지우기
필터 지우기

How do I delete columns from a matrix based on an array

조회 수: 2 (최근 30일)
ozan aksu
ozan aksu 2017년 3월 20일
댓글: kowshik Thopalli 2017년 3월 20일
I have matrix of A=[4 3 5 6 7; 1 4 8 4 7] and B=[3 6 7] and i want do delete columns of A which's first row contain the values of B and have the answer; A= [4 5; 1 8]
thank you

채택된 답변

James Tursa
James Tursa 2017년 3월 20일
A(:,ismember(A(1,:),B)) = [];

추가 답변 (1개)

kowshik Thopalli
kowshik Thopalli 2017년 3월 20일
As you can imagine there is more than one way to do this. here is one method.Not elegant but works
A=[4 3 5 6 7; 1 4 8 4 7];B=[3 6 7];
[ismem index] = ismember(A(1,:),B)
i=repmat(index,[2,1]
A(i~=0)=[]
reshape(A,2,2)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by