MATLAB Answers

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

3 views (last 30 days)
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

  0 Comments

Sign in to comment.

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 27 Nov 2019
Edited: Andrei Bobrov on 28 Nov 2019
out = all(A <= 1,2).*A

Sign in to answer this question.