"Or" statement and "not equal to" signal

2 ビュー (過去 30 日間)
Miguel Cardoso
Miguel Cardoso 2020 年 4 月 14 日
編集済み: Miguel Cardoso 2020 年 4 月 14 日
Good night!
I have a matrix (I will give as an example M) with three columns and N rows, where M(:,1) and M(:,2) varies between 1 and 4.
M=[ 1 2 9
2 3 6
3 4 5
4 4 3
2 3 8];
I want to rewritte M removing the rows where M(:,1) or M(:,2) are different from 4. I tried :
if(M(:,1)~=4)|(M(:,2)~=4)
m=M;
end
I would like that my final matrix would be:
m=[1 2 9
2 3 6
2 3 8];
Unfortunatelly, my code is not given the desired result.
Hope you can help me!

採用された回答

Delprat Sebastien
Delprat Sebastien 2020 年 4 月 14 日
% find rows that does not contains 4 in col 1 & 2
rowOk=(M(:,1)~=4) & (M(:,2)~=4)
% Use logical indexing to keep these row
m=M(rowOk,:)
  1 件のコメント
Miguel Cardoso
Miguel Cardoso 2020 年 4 月 14 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by