MATLAB Answers

adena0
0

How to index a random matrix with set conditions?

Asked by adena0
on 14 Jan 2019
Latest activity Answered by Are Mjaavatten on 14 Jan 2019
How can I find elements within a random matrix M (5x5) that are negative or are between 20 and 40?

  0 Comments

Sign in to comment.

Products


Release

R2018a

1 Answer

Answer by Are Mjaavatten on 14 Jan 2019
 Accepted Answer

For a list of the negative values:
negM = M(M<0)
For the indices of the negative values:
[i,j] = find(M<0)
To display only the negative values in a matrix:
N = M;
N(N>=0) = 0
For values between 20 and 40
values = M(M>=20 & M<=40)

  0 Comments

Sign in to comment.