hi all,
Good day! pretty new to matlab, and used to be a java programmer that is more familiar with for loops. I do know there are certain elegance in matlab by using some Matlab functions on matrix / arrays.
I have a simple problem that i think can be resolved without a for loop, and i think we can use the "All" function in Matlab but i couldn't grasp it just yet.
I have the below data.
36 -31
36 -27
0 0
35 -30
0 0
32 -30
0 0
31 -30
0 0
32 -30
, just wanted to remove the whole row if both values are 0 in the same row. Is it possible without doing a for loop? Thank you!
Darren

 채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 1월 2일
편집: KALYAN ACHARJYA 2021년 1월 2일

1 개 추천

Another way
result=data(~(data(:,1)==0 & data(:,2)==0),:)
result =
36 -31
36 -27
35 -30
32 -30
31 -30
32 -30

추가 답변 (1개)

Alan Stevens
Alan Stevens 2021년 1월 2일
편집: Alan Stevens 2021년 1월 2일

1 개 추천

Here's one way:
ix = (M(:,1)+M(:,2))==0;
M(ix,:) = [];

댓글 수: 1

Darren Lim
Darren Lim 2021년 1월 2일
thanks Alan,
this works as well ! learnt a lot today!
Darren

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2021년 1월 2일

댓글:

2021년 1월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by