How to select a column on basis of some conditions on the rows?

1 回表示 (過去 30 日間)
Armando MAROZZI
Armando MAROZZI 2020 年 11 月 18 日
コメント済み: Armando MAROZZI 2020 年 11 月 18 日
I have a situation where I have a 6x100 matrix like the one below:
x = randn(6,100)
What I would like to do is to write a code that says: for every column in x keep only those columns whose first and second rows have positive entries, while the fourth one has a negative entry. So let's take two representative columns like the ones below:
0.5 0.3
3.1 0.2
0.6 0.6
0.8 -0.9
0.1 -1
0.3 1
The code should exclude the first column and keep the second; this for every column in x.
Can anyone help me with that?
Thanks!

採用された回答

Timo Dietz
Timo Dietz 2020 年 11 月 18 日
編集済み: Timo Dietz 2020 年 11 月 18 日
Does this solve your problem?
x = x(:, x(1, :) > 0 & x(2, :) > 0 & x(4, :) < 0)
  1 件のコメント
Armando MAROZZI
Armando MAROZZI 2020 年 11 月 18 日
thanks a lot! Easier than thought once I see it ! thanks again

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by