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.

3 件のコメント

Muthu Annamalai
Muthu Annamalai 2013 年 9 月 13 日
Smells like homework to me :-)
Matt Kindig
Matt Kindig 2013 年 9 月 13 日
編集済み: Matt Kindig 2013 年 9 月 13 日
Can you use the built-in function hist()? If you can, this is trivially easy:
doc hist

サインインしてコメントする。

 採用された回答

Roger Stafford
Roger Stafford 2013 年 9 月 13 日
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 ExchangeSpline Postprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by