1

I have a table that has a column containing values between 1 and 20. I want to filter the table such that I can show only certain discrete values, i.e. 3, 10, 12, and 19. The problem is writing this is cumbersome, especially since I want to write other criteria for filtering too.:

i = tb.subn==3 | tb.subn==10 | tb.subn==12 | tb.subn==19 

If I use i = tb.subn==[3 10 12 19] then I get a :x4 boolean matrix. How can I get that into just one column?

If it were &, I suppose I could use prod(tb.subn==[3 10 12 19],2) but I can't figure out or.

Thanks.

Pac0
  • 21,465
  • 8
  • 65
  • 74
teepee
  • 2,620
  • 2
  • 22
  • 47

2 Answers2

1
i = all(tb.subn==[3 10 12 19], 2);

Note that this works only for very late matlab, while you solution will work better for all versions.

Xiangrui Li
  • 2,386
  • 2
  • 13
  • 17
1

You can use ismember(tb.subn, [3, 10, 12, 19])

G.J
  • 795
  • 1
  • 6
  • 12