Replacing all elements in a row with zeros, if atleast one of the elements in the row is greater than 1

1 回表示 (過去 30 日間)
Good day,
Please how can I replace all elements of a row with zeros if any of the elements in the row is greater than 1.
For instance; I have a 4X3 Matrix;
A= [0.2 0.5 0.1
0.4 0.6 3.0
0.2 0.5 0.1
2.0 0.5 0.1]
Only raw 2 and row 4 contain element that is greater than 1.
so the output will be = [0.2 0.5 0.1
0.0 0.0 0.0
0.2 0.5 0.1
0.0 0.0 0.0]
Thanks in anticipation of your help

採用された回答

James Tursa
James Tursa 2019 年 11 月 27 日
Another method if you want the replacement in-place:
A(any(A>1,2),:) = 0;

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2019 年 11 月 27 日
編集済み: Andrei Bobrov 2019 年 11 月 28 日
out = all(A <= 1,2).*A
  2 件のコメント
AUWAL ABUBAKAR
AUWAL ABUBAKAR 2019 年 11 月 28 日
Thanks for your response.
But when I run it, I got exactly the same matrix as A.
The response by James below solved my problem.
thanks

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

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by