fastmode
by Harold Bien
13 Apr 2006
(Updated 14 Apr 2006)
Optimized high speed version of statistical mode, i.e. element(s) occuring at greatest frequency
|
Watch this File
|
| File Information |
| Description |
fastmode is an improvement on 'mode.m' by Michael Robbins (File ID 5266). It ignores NaN's and properly returns multiple results if more than one element occurs at equal frequency.
M-file profiler revealed extracting unique values took 50% of the time spent in the function, and since a list of unique values were not required, a work-around has been used that makes this even faster than the first submission (25 seconds to process a 100,000 element vector iterated 1,000 times, versus original 27 seconds and Robbins' hist-based version of 69 seconds).
The function is rather robust in that it can handle even single-element vectors, but it will generate an error if you attempt to call it with an empty vector. Since it's designed for speed, no error checking is performed on the input. |
| Acknowledgements |
The author wishes to acknowledge the following in the creation of this submission:
mode
This submission has inspired the following:
mode calculator
|
| MATLAB release |
MATLAB 7.0.4 (R14SP2)
|
|
Tags for This File
|
| Everyone's Tags |
|
| Tags I've Applied |
|
| Add New Tags |
Please login to tag files.
|
| Comments and Ratings (6) |
| 13 Dec 2006 |
Mukhtar Ullah
|
|
|
| 15 Dec 2006 |
Harold Bien
|
|
|
| 15 Dec 2006 |
Harold Bien
|
|
|
| 17 Dec 2006 |
Mukhtar Ullah
|
|
|
| 17 Dec 2006 |
Mukhtar Ullah
|
|
|
| 19 Dec 2006 |
Harold Bien
|
|
|
|
Contact us at files@mathworks.com