Deleting every row with a zero in the first column, except the first row

5 Ansichten (letzte 30 Tage)
I have the following Matrix A
A = [0 0; 2 5; 3 6; 7 0; 0 5; 0 3]
I'd like to delete every row that has a 0 in the first column, except the first one.
So thats my code so far
A(all(A(2:end,1)==0,2),:)=[];
it works just as I'd like it to, but it always deletes the 4th row and gives me instead the last one.
Thanks for any help

Akzeptierte Antwort

Alex Mcaulley
Alex Mcaulley am 11 Jun. 2019
Try this:
A([false;~A(2:end,1)],:) = []

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices 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!

Translated by