필터 지우기
필터 지우기

How to index all columns but one in a matrix?

조회 수: 70 (최근 30일)
Peter
Peter 2013년 8월 2일
댓글: James Tursa 2018년 8월 3일
Hi!
I want to do index/use all columns in a matrix but a single one, so for example:
A=[1 2 3 4; 1 2 3 4; 1 2 3 4] and I 'd like to get at B=[1 2 4; 1 2 4; 1 2 4].
A long way to that would be: B=[A(:,1:2),A(:,4)], but is there anything faster/built in?
Best Peter

채택된 답변

James Tursa
James Tursa 2013년 8월 2일
B = A;
B(:,3) = [];
  댓글 수: 7
Brando Miranda
Brando Miranda 2018년 8월 3일
why does X([1 1 0 1]) not work?
James Tursa
James Tursa 2018년 8월 3일
Because [1 1 0 1] is not a logical vector and you are not accounting for both dimensions. E.g., compare your code to this:
X(:,logical([1 1 0 1]))

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

추가 답변 (1개)

David Sanchez
David Sanchez 2013년 8월 2일
% no need of a new matrix, remake the old one:
A = exp(A(:,[1:2,4]));

카테고리

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