How to extract matrix from a bigger matrix based on threshold of each column?

2 ビュー (過去 30 日間)
Mathieu Morel
Mathieu Morel 2019 年 12 月 2 日
編集済み: Adam Danz 2019 年 12 月 2 日
I have a nX3 matrix. I need to extract a matrix such that all rows crossing the threshold of each column are selected. Threshold can be assumed to be 100(column 1),200(column2) and 300(column 3 )? Please help...
  1 件のコメント
Adam Danz
Adam Danz 2019 年 12 月 2 日
Small examples of inputs and expected outputs are usually worth 1000 words.

サインインしてコメントする。

採用された回答

Philippe Lebel
Philippe Lebel 2019 年 12 月 2 日
編集済み: Philippe Lebel 2019 年 12 月 2 日
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
  4 件のコメント
Philippe Lebel
Philippe Lebel 2019 年 12 月 2 日
nice one, I forgot about all()
thanks for the input
Adam Danz
Adam Danz 2019 年 12 月 2 日
編集済み: Adam Danz 2019 年 12 月 2 日
Nice job interpreting the question. I wouldn't have guessed. Too many times I guessed on other questions, spent time writing out the solution, and then found that my interpretation wasn't correct.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by