4

I was wondering if there is a function like the one (smaller) below, but instead extracts values that are unequal to zero?

a = [67 0 8 25 0 20 0 90 7 2 9];

smaller10 = a(a < 10)

smaller10 =

 0     8     0     0     7     2     9
timgeb
  • 76,762
  • 20
  • 123
  • 145
Kim Portu
  • 41
  • 2
  • 1
    What's the programming language? Looks like matlab or octave. I can answer your question if it is one of those, but you have to provide that information. – timgeb Feb 09 '16 at 20:09
  • Of course, I'm sorry. It's MATLAB ;) – Kim Portu Feb 09 '16 at 20:39
  • 2
    All you wanted to know about indexing in Matlab: http://stackoverflow.com/questions/32379805/linear-indexing-logical-indexing-and-all-that – Marc Feb 09 '16 at 20:48

1 Answers1

3

Either use

a(a~=0)

or

nonzeros(a).'

You can find the documentation for nonzeros here.

timgeb
  • 76,762
  • 20
  • 123
  • 145