MATLAB Answers

How to eliminate certain columns from a matrix

조회 수: 6(최근 30일)
Hatake nara
Hatake nara 13 Jun 2019
답변: Manvi Goel 13 Jun 2019
If I need to remove any column how do I do it?
For example:
s is a mxn matrix.I need to remove the odd columns i,e, the 1st,3rd.. columns.

  댓글 수: 0

로그인 to comment.

채택된 답변

KSSV
KSSV 13 Jun 2019
편집: KSSV 13 Jun 2019
Let A be matrix
A(:,1:2:end) = [] % remove odd columns
A(:,3) = [] % remove third column
idx = [1 2 5 7] ;
A(:,idx) = [] % remove columns specified in idx

  댓글 수: 0

로그인 to comment.

추가 답변(1개)

Manvi Goel
Manvi Goel 13 Jun 2019
Let the matrix be a.
You can remove the odd columns of a matrix by :
a(:,1:2:end) = []
% 1:2:end runs a loop from 1 till the numbe rof columns, increments the index by 2 every time and
% empties the column with that index.
Or use the following command to remove and column with index 'i'
a(:, i) = []

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by