How to delete row from matrix, which has values 0 and 4?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Beibit Sautbek
am 21 Jul. 2016
Bearbeitet: Stephen23
am 21 Jul. 2016
I have a matrix:
u =
0 0 4
0 3 0
0 3 4
2 0 0
2 0 4
2 3 0
2 3 4
I need to delete a row which has value 4 and other values equal to 0.
So, my result should delete the first row, where [0 0 4]. How Can I do?
I did this code below, but it doesn't work.
d=length(u);
if u(1:d,:)==0 & u(1:d,:)==4
u(1:d,:) = []
end
Could anyone help me?
0 Kommentare
Akzeptierte Antwort
Stephen23
am 21 Jul. 2016
Bearbeitet: Stephen23
am 21 Jul. 2016
u = [...
0 0 4
0 3 0
0 3 4
2 0 0
2 0 4
2 3 0
2 3 4]
idx = all(u==0 | u==4, 2)
out = u(~idx,:)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!