Deleting certain columns in a matrix
51 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mate 2u
am 15 Jul. 2012
Kommentiert: Craig Champlin
am 5 Dez. 2019
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 Kommentare
Mayank Malaviya
am 2 Sep. 2016
Bearbeitet: Mayank Malaviya
am 2 Sep. 2016
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
am 26 Nov. 2018
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).
Akzeptierte Antwort
Weitere Antworten (1)
Reza Zakernejad
am 12 Okt. 2017
Bearbeitet: Reza Zakernejad
am 12 Okt. 2017
A(:,[m n p...])=[]; % A input matrix and m n p are #columns to be deleted
1 Kommentar
Craig Champlin
am 5 Dez. 2019
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
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!