JHnet
JHnet

Reputation: 471

How to get a matrix row conditionally?

In matlab I have a variable X containing training data (rowwise). Additionally there is a variable S with the class of the data. How to get all entries of X with a specific (e.g. negative) class ?

Example:

X = [1 2;3 4;5 6;7 8;9 10];
S = [1 -1 -1 1 -1];

Should give:

ans = [3 4;5 6;9 10];

Upvotes: 3

Views: 34

Answers (1)

LowPolyCorgi
LowPolyCorgi

Reputation: 5171

You simply have to do:

X(S<0,:)

This array will contain the rows of X for which S is negative.

Best

Upvotes: 5

Related Questions