Deleting Entries in an Array
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hans123
am 29 Jan. 2019
Kommentiert: Hans123
am 30 Jan. 2019
I am working with a 1627x11 array, labelled A, and I want to delete the entries that have 0 in the 9th column (i.e delete the whole row).
V = A(:,9);
vals=find(V==0);
A(vals)=[ ];
after running that code, the array converts to an 1x16617 double - which is not wat I anticipated nor want.
To reiterate, the 9th column which has a sort of counter is used to keep track of which point I am working with, and I do not want to include the rows which are in the 0th point.
Rows 0 to 1280 contains 0 in the 9th column (this was done by observing the array), so I should have a 347x11 array after running the code.
What am I doing wrong
0 Kommentare
Akzeptierte Antwort
Brian Hart
am 29 Jan. 2019
Hi Ramitha,
You almost got it. For your last line of code, try
A(vals,:)=[];
The way you tried it at first uses linear lindexing (see sub2ind)
3 Kommentare
Stephen23
am 30 Jan. 2019
Simpler and more efficient to use logical indexing (without find):
A(A(:,9)==0,:) = [];
Weitere Antworten (1)
madhan ravi
am 29 Jan. 2019
Bearbeitet: madhan ravi
am 30 Jan. 2019
A(~any(A(:,9),2),:)=[]
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays 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!