Mode in Matlab

Started by July 21, 2004
 Hi, Do any body know, How to find out mode (most occuring number in array/matrix) in Matlab? Or do you have program code to find mode? Regards, Tarendra Lakhankar
 Hi, The following code was posted to Matlab Central, by Michael Robbins: (http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectIdR 66&objectType=file) function y=mode(x) % MODE finds the mode of a sample. The mode is the % observation with the greatest frequency. % % i.e. in a sample x=[0, 1, 0, 0, 0, 3, 0, 1, 3, 1, 2, 2, 0, 1] % the mode is the most frequent item, 0. % IT'S NOT FANCY BUT IT WORKS % Michael Robbins % % [b,i,j] = unique(x); [m,k]=max(hist(j,length(b))); y=b(k); Jeff -----Original Message----- From: tlakhankar [mailto:] Sent: Wednesday, July 21, 2004 10:03 PM To: Subject: [matlab] Mode in Matlab Hi, Do any body know, How to find out mode (most occuring number in array/matrix) in Matlab? Or do you have program code to find mode? Regards, Tarendra Lakhankar _____________________________________ Note: If you do a simple "reply" with your email client, only the author of this message will receive your answer. You need to do a "reply all" if you want your answer to be distributed to the entire group. _____________________________________ About this discussion group: To Join: To Post: To Leave: Archives: http://www.yahoogroups.com/group/matlab More DSP-Related Groups: http://www.dsprelated.com/groups.php3 Yahoo! Groups Links
 Tarendra- There mite be a function to do that, heres how i would have done it. few assumptions that have gone lets say X is the array in which you want to find mode. fnd histogram of that array. Thing you should take care is the number of buckets you are going to use.  for e.g. if range of number is from 1 -  100 integers then  number of buckets would be 100. code would be something like this X = 100 *rand(1,1000); X = round(X);  % range will be from 0 - 100. in discrete steps of 1. Y = hist(X,101); Index = find( Y == max(Y)); Index variable will contain all the index (i.e number )  which appears maximum number of time. I understand this is round about and crude way of finding that number. Also you may have to modify the code to suit ur application. Hope this helps -Tarang On Thu, 22 Jul 2004 tlakhankar wrote :>Hi, >Do any body know, How to find out mode (most occuring number in >array/matrix) in Matlab? >Or do you have program code to find mode? >Regards, >Tarendra Lakhankar >_____________________________________ >Note: If you do a simple "reply" with your email client, only the author of this message will receive your answer.  You need to do a "reply all" if you want your answer to be distributed to the entire group. >_____________________________________ >About this discussion group: >To Join:  m...@yahoogroups.com >To Post:  m...@yahoogroups.com >To Leave: m...@yahoogroups.com >Archives: >http://www.yahoogroups.com/group/matlab >More DSP-Related Groups: >http://www.dsprelated.com/groups.php3 > >Yahoo! Groups Links >To BR> >. > Tarang Dadia Graduate Student Wireless Networking Lab University of Texas at Arlington.