Matlab, how to filter a numerical vector by condition?

In Matlab, I have an X vector containing N real values:

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

I would like to create a new vector Xb containing all the values ​​of M for X that are less than 0.005 (M <= N). How can i do this?

I tried:

Xb = X <0.005

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

Thanx

+6
source share
2 answers
>> Xb = X(X < 0.005) Xb = 0.0010 0.0030 
+14
source

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

+2
source

Source: https://habr.com/ru/post/904769/


All Articles