How to write a program to take mode of vector without using built in function 'mode'?

We are using Matlab. We cannot develop an algorithm and need very descriptive and specific steps as to how to solve our question.

 채택된 답변

If you are not permitted to use matlab's 'mode' function, and if your vector is a column vector called v, do this:
s = sort(v);
[~,p] = max(diff(find([true;diff(s)~=0;true])));
md = s(p); % <-- This is the most frequent value in v

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2013년 9월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by