Removing row of a nx3 matrix if at any row the 3rd column is 0
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Quoc Khang Doan
il 24 Mag 2021
Commentato: Quoc Khang Doan
il 24 Mag 2021
I tried doing this using a for loop and come to realise it is impossible to, can anyone tell me a way to remove a row of a matrix if the condition is met
for example:
b =
1 2 0
3 4 5
3 2 -1
5 6 0
1 3 6
with the above matrix b, how do I go thru each row and check if the 3rd column is either less than or equal to 0 and remove it?
0 Commenti
Risposta accettata
David Fletcher
il 24 Mag 2021
Modificato: David Fletcher
il 24 Mag 2021
b = [1 2 0;3 4 5;3 2 -1;5 6 0;1 3 6]
idx=b(:,3)<=0
b(idx,:)=[]
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!