How to get a matrix row conditionally?

In Matlab, I have a variable X containing training data (rollise). In addition, there is a variable S with a data class. How do I get all X records with a special (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];

      

+3


source to share


1 answer


You just need to do:

X(S<0,:)

      



This array will contain strings X

for which is S

negative.

The best

+5


source







All Articles