Given a matrix A
, how do I get the elements (and their indices) larger than x
in a specific range?
e.g.
A = [1:5; 2:6; 3:7; 4:8; 5:9]
A =
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
And for instance I want all elements larger than 5 and appear in the range A(2:4,3:5)
. I should get:
elements:
6 , 6 , 7 , 6 , 7 , 8
indices:
14, 18, 19, 22, 23, 24
A(A>5)
would give me all entries which are larger than 5.
A(2:4,3:5)
would give all elements in the range 2:4,3:5
.
I want some combination of the two. Is it possible or the only way is to put the needed range in another array B
and only then perform B(B>5)
? Obviously 2 problems here: I'd lose the original indices, and it will be slower. I'm doing this on a large number of matrices.