MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Learn moreOpportunities for recent engineering grads.
Apply TodayMATLAB Central > MATLAB Newsreader > A function to count the number of occurrances 

Subject: A function to count the number of occurrances From: Rawley Date: 12 Jan, 2011 20:24:04 Message: 1 of 16 
I'm trying to see if there's a more efficient way to write this function. I need to be able to count the number of occurrences of an integer in a vector up to each element. For example if I have a vector with identifiers in the first column and I want to count the number of occurrences it's appeared up to that point: 
Subject: A function to count the number of occurrances From: zheng Date: 12 Jan, 2011 20:39:04 Message: 2 of 16 
"Rawley " <ballheim@gmail.com> wrote in message <igl2l4$h11$1@fred.mathworks.com>... 
Subject: A function to count the number of occurrances From: Sean de Date: 12 Jan, 2011 20:39:04 Message: 3 of 16 
"Rawley " <ballheim@gmail.com> wrote in message <igl2l4$h11$1@fred.mathworks.com>... 
Subject: A function to count the number of occurrances From: Sean de Date: 12 Jan, 2011 20:42:04 Message: 4 of 16 
Actually, even easier: 
Subject: A function to count the number of occurrances From: Jan Simon Date: 12 Jan, 2011 20:59:05 Message: 5 of 16 
Dear Rawley, 
Subject: A function to count the number of occurrances From: Bruno Luong Date: 12 Jan, 2011 21:23:04 Message: 6 of 16 
Or this, a 100% vectorized Matlab solution: 
Subject: A function to count the number of occurrances From: Bruno Luong Date: 12 Jan, 2011 21:44:06 Message: 7 of 16 
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <igl63o$37i$1@fred.mathworks.com>... 
Subject: A function to count the number of occurrances From: Rawley Date: 12 Jan, 2011 22:09:07 Message: 8 of 16 
Wow! Thanks everyone for the help. Life savers! 
Subject: A function to count the number of occurrances From: Rawley Date: 14 Jan, 2011 03:03:05 Message: 9 of 16 
I have a similar code that I need a more efficient solution to. I need to count the number of times real valued elements have occurred per unique identifier. The first column is the unique identifier and the third column is the occurrence. Input: 
Subject: A function to count the number of occurrances From: Paulo Silva Date: 14 Jan, 2011 04:18:04 Message: 10 of 16 
"Rawley " <ballheim@gmail.com> wrote in message <igoed9$fhd$1@fred.mathworks.com>... 
Subject: A function to count the number of occurrances From: Bruno Luong Date: 14 Jan, 2011 07:06:06 Message: 11 of 16 
"Rawley " <ballheim@gmail.com> wrote in message <igoed9$fhd$1@fred.mathworks.com>... 
Subject: A function to count the number of occurrances From: Rawley Date: 14 Jan, 2011 14:15:07 Message: 12 of 16 
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <igosku$s11$1@fred.mathworks.com>... 
Subject: A function to count the number of occurrances From: Rawley Date: 15 Jan, 2011 18:18:04 Message: 13 of 16 
I hate to followup with this question again, but I'm completely striking out on my own. Thanks for the help, Paulo, but I really do need a vectorized solution because my data is way too big to run loops on. 
Subject: A function to count the number of occurrances From: Bruno Luong Date: 15 Jan, 2011 22:37:04 Message: 14 of 16 
Try that: 
Subject: A function to count the number of occurrances From: Bruno Luong Date: 16 Jan, 2011 09:51:04 Message: 15 of 16 
I'm not sure why my post of a simplified version of fixing the issue of restarting does not appear in TMW Newsgroup page, so I post it again. Apologize if the post appears twice: 
Subject: A function to count the number of occurrances From: Rawley Date: 16 Jan, 2011 16:20:05 Message: 16 of 16 
Bruno = lifesaver. Thank you very very much! 
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.