user3766332
user3766332

Reputation: 329

Select column from matrix where some other column satisfies given condition

My matrix has 10 columns. I want to select all rows where the first column is less than 4. If I use

data(data(:,1)<4)

Only the first column is selected.
How do I display all corresponding column values?
How do I select a single corresponding column, e.g., select column 2 where value of column1<4?

Upvotes: 0

Views: 575

Answers (2)

lakshmen
lakshmen

Reputation: 29104

data(data(:,1)<4,:)

: indicates all columns. Since data is 2-d matrix, you need to input two parameters, one for row and one for column.

If you need specific columns like column 2

data(data(:,1)<4,2)

Upvotes: 2

Shai
Shai

Reputation: 114986

How about

data( data(:,1) < 4, : )

Upvotes: 4

Related Questions