How to select a column on basis of some conditions on the rows?
4 views (last 30 days)
Show older comments
Commented: Armando MAROZZI on 18 Nov 2020
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:
The code should exclude the first column and keep the second; this for every column in x.
Can anyone help me with that?
Timo Dietz on 18 Nov 2020
Edited: Timo Dietz on 18 Nov 2020
Does this solve your problem?
x = x(:, x(1, :) > 0 & x(2, :) > 0 & x(4, :) < 0)
More Answers (0)
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!