Sign in

username or email:

password:



Not a member?
Forgot your password?

Search matlab



Search tips

Subscribe to matlab



Ads

Discussion Groups

See Also

Embedded SystemsFPGA

Discussion Groups | Matlab DSP | 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 ...

  

Post a new Thread



Is this thread worth a thumbs up?

0

Mode in Matlab - tlakhankar - Jul 21 21:03:00 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




______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

RE: Mode in Matlab - Jeff Winter - Jul 22 12:51:00 2004

Hi,

The following code was posted to Matlab Central, by Michael Robbins:
(http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=52
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
_____________________________________
/groups.php3
Yahoo! Groups Links






(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: Mode in Matlab - tArAng - Jul 22 21:09:00 2004

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
>_____________________________________
>/groups.php3
>Yahoo! Groups Sponsor
>ADVERTISEMENT
>Yahoo! Groups Links
>To BR> >.
>

Tarang Dadia
Graduate Student
Wireless Networking Lab
University of Texas at Arlington.
______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )