Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab, how to filter a numeric vector by a condition?

In Matlab, I have a vector, X, that contains N real values:

  • 0.001
  • 0.003
  • 0.006
  • 0.009
  • 0.007
  • 0.006

I would like to create a new vector, Xb, that contains all the M values of X that are less than 0.005 (M <= N). How could I do it?

I've tried with:

Xb = X<0.005

but it gives me a vector of N values 0s or 1s.

Thanx

like image 829
DavideChicco.it Avatar asked Dec 30 '11 18:12

DavideChicco.it


Video Answer


2 Answers

>> Xb = X(X < 0.005)

Xb =

    0.0010    0.0030
like image 71
jlrcowan Avatar answered Nov 15 '22 07:11

jlrcowan


What you did with the code Xb=X<0.005 was to create a mask. Simply put, it tells you which values are less than 0.005, but with no sorting of the list. What you want is to sort the list by the mask, which can be done as jlrcowan has suggested.

like image 31
PearsonArtPhoto Avatar answered Nov 15 '22 06:11

PearsonArtPhoto