Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab - count how many times a number occurs

  1. Aug 17, 2010 #1
    Suppose

    x =

    1 2 3 4
    1 2 3 4
    5 6 7 8
    1 2 3 4
    5 6 7 8

    I need a function to count how many times each set of number occurs
    eg.
    1 2 3 4 occurs 3 times
    5 6 7 8 occurs 2 times

    Thanks!
     
    Last edited: Aug 17, 2010
  2. jcsd
  3. Aug 17, 2010 #2
    Off the top of my head, you could try:

    sum(x == 2)

    To count the number of times 2 appears.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook