1 view (last 30 days)

Philippe Lebel
on 2 Dec 2019

Edited: Philippe Lebel
on 2 Dec 2019

here is my try based on what i understood.

given a matrix a nx3:

a = [5,6,8;1,2,3;2,3,4;3,4,5;4,5,6]

a =

5 6 8

1 2 3

2 3 4

3 4 5

4 5 6

% the threshold on column 1 is 2

a_1 = a(a(:,1)>2,:)

a_1 =

5 6 8

3 4 5

4 5 6

% the treshold on column 2 is 4

a_2 = a_1(a_1(:,2)>4,:)

a_2 =

5 6 8

4 5 6

%the treshold on column 3 is 6

a_3 = a_2(a_2(:,3)>6,:)

a_3 =

5 6 8

a_3 is the matrix containing the row(s) that satisfy all tresholds.

A one-liner can be made for this operation:

a_tresh = a((a(:,1)>2)&(a(:,2)>4)&(a(:,3)>6),:)

a_tresh =

5 6 8

Adam Danz
on 2 Dec 2019

This can be simplified and reduced to

a = [5,6,8;1,2,3;2,3,4;3,4,5;4,5,6];

thresh = [2,4,6]; % Row vector defining the threshold of each column of 'a'

a(all(a > thresh,2),:)

% ans =

% 5 6 8

Adam Danz
on 2 Dec 2019

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

Start Hunting!
## 1 Comment

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/494349-how-to-extract-matrix-from-a-bigger-matrix-based-on-threshold-of-each-column#comment_773511

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/494349-how-to-extract-matrix-from-a-bigger-matrix-based-on-threshold-of-each-column#comment_773511

Sign in to comment.