How to eliminate certain columns from a matrix

172 ビュー (過去 30 日間)
Hatake nara
Hatake nara 2019 年 6 月 13 日
回答済み: Manvi Goel 2019 年 6 月 13 日
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.

採用された回答

KSSV
KSSV 2019 年 6 月 13 日
編集済み: KSSV 2019 年 6 月 13 日
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

その他の回答 (1 件)

Manvi Goel
Manvi Goel 2019 年 6 月 13 日
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) = []

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by