No BSD License  

Highlights from
Statistical Mode

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 3.84 KB File ID: #6822

Statistical Mode

by Muneem Shahriar

 

28 Jan 2005 (Updated 02 Feb 2005)

Finds the "mode" (most occuring element) in a 1D number REAL array

| Watch this File

File Information
Description

Mode function for MATLAB 6.1 or above

Syntax: [mode,modal,times] = ms_modal(x);
where :
x is the 1-D input array consisting of REAL numbers, in either row or columnar form modal is the output which consists of the numbers appearing in array x. It has each number once only. This is not sorted.

times is the array which records how many times each corresponding number in modal occurs

Example:
        x = [1 2 3 4 1 1 2]
        [mode,modal,times] = ms_modal(x);
 gives:
 mode = 1
 modal =
 
      1 2 3 4 0 0
 
 
 times =
 
      3 2 1 1 0 0

Created by Muneem Shahriar (muneem.shahriar@ttu.edu)

*************************************

LIMITATION: ONLY OUTPUTS 1 ELEMENT AS THE MODE.

Let me know if you run into problems!

MATLAB release MATLAB 6.1 (R12.1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
02 Feb 2005 Muneem Shahriar

Just a little correction: This function does not find the "mode" in a character array, although it something it can address with some little additional programming.

Limitation: Displays a single mode only even if other numbers occur the same number of times.

30 Jul 2007 Felix Hebeler

Apparently doesnt work if negative numbers are present...

Please login to add a comment or rating.
Updates
02 Feb 2005

Found a small bug the other night, corrected the problem with index in finding mode.

Tag Activity for this File
Tag Applied By Date/Time
statistics Muneem Shahriar 22 Oct 2008 07:40:21
probability Muneem Shahriar 22 Oct 2008 07:40:21
mode Muneem Shahriar 22 Oct 2008 07:40:21
modal Muneem Shahriar 22 Oct 2008 07:40:21
times Muneem Shahriar 22 Oct 2008 07:40:21
1d array Muneem Shahriar 22 Oct 2008 07:40:21

Contact us at files@mathworks.com