Deleting certain columns in a matrix

110 次查看(过去 30 天)
Hi all,
I have a 267x34 matrix. Now I want to delete certain columns within MATLAB.
For instance if I want to delete the 3rd column, 4th column, 8th column, 14th column and 33 column. How would I write this in a code where they all get delete simultaneously?
Thanks,
  2 个评论
Mayank Malaviya
Mayank Malaviya 2016-9-2
编辑:Mayank Malaviya 2016-9-2
B = horzcat(A(1:end,1:n-1),A(1:end,n+1:end)); % A is your matrix and n is the column which is to be removed
Fabian Lischka
Fabian Lischka 2018-11-26
FWIW, above comment from 2016-09-02 does not address the question (deleting multiple columns), and is furthermore possibly a fairly inefficient way of doing what it does (deleting one column).

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2012-7-15

更多回答(1 个)

Reza Zakernejad
Reza Zakernejad 2017-10-12
编辑:Reza Zakernejad 2017-10-12
A(:,[m n p...])=[]; % A input matrix and m n p are #columns to be deleted
  1 个评论
Craig Champlin
Craig Champlin 2019-12-5
Not sure why this is not the "Accepted Answer". It does exactly what I want to. I have several column indexes of outliers which I found by comparing against a threshold. Using this answer, I can simply put my list into the [] and poof outliers are gone.
outliers = find (errorDist > thresholdValue); % list of outliers
M(:,outliers) = []; % *poof!* clean matrix

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by