Statistical Mode

Finds the "mode" (most occuring element) in a 1D number REAL array
1K Downloads
Updated 2 Feb 2005

No License

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!

Cite As

Muneem Shahriar (2024). Statistical Mode (https://www.mathworks.com/matlabcentral/fileexchange/6822-statistical-mode), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R12.1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Structures in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0

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