MATLAB: Extract data from each row in a matrix if all columns in that row above a threshold

allextractthresshold

I have a matrix of 10 rows & 5 columns I need to compare the data in each row to a threshold so for a specific row if all the columns values are above a threshold then I need to extract that row into another matrix. Can anyone help me to do this please
Many Thanks in advance

Best Answer

Here is an example:
>> A = randi( 20, 10, 5 ) % Dummy example.
A =
17 4 14 15 9
19 20 1 1 8
3 20 17 6 16
19 10 19 1 16
13 17 14 2 4
2 3 16 17 10
6 9 15 14 9
11 19 8 7 13
20 16 14 20 15
20 20 4 1 16
>> threshold = 4 ;
>> B = A(all( A > threshold, 2 ),:)
B =
6 9 15 14 9
11 19 8 7 13
20 16 14 20 15
PS: if you need to remove these rows, you can do it as follows:
>> isAllAbove = all( A > threshold, 2 ) ;
>> B = A(isAllAbove,:)
B =
6 9 15 14 9
11 19 8 7 13
20 16 14 20 15
>> A(isAllAbove,:) = [] % or A = A(~isAllAbove,:)
A =
17 4 14 15 9
19 20 1 1 8
3 20 17 6 16
19 10 19 1 16
13 17 14 2 4
2 3 16 17 10
20 20 4 1 16