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 件のコメント

Darren Lim
Darren Lim 2021 年 1 月 2 日
thank you Kalyan, this works ! :)

サインインしてコメントする。

その他の回答 (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 で Matrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by