# Removing row of a nx3 matrix if at any row the 3rd column is 0

조회 수: 2(최근 30일)
Quoc Khang Doan 2021년 5월 24일
댓글: Quoc Khang Doan 2021년 5월 24일
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?

댓글을 달려면 로그인하십시오.

### 채택된 답변

David Fletcher 2021년 5월 24일
편집: David Fletcher 2021년 5월 24일
b = [1 2 0;3 4 5;3 2 -1;5 6 0;1 3 6]
b = 5×3
1 2 0 3 4 5 3 2 -1 5 6 0 1 3 6
idx=b(:,3)<=0
idx = 5×1 logical array
1 0 1 1 0
b(idx,:)=[]
b = 2×3
3 4 5 1 3 6
##### 댓글 수: 1표시숨기기 없음
Quoc Khang Doan 2021년 5월 24일
ty sir

댓글을 달려면 로그인하십시오.

### 범주

Find more on Matrix Indexing in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by