matlab统计一个数组中各元素出现的频数、频率

原文:http://blog.163.com/sunkun_hust/blog/static/204454119201292393252247/


原文出处:http://www.matlabsky.com/thread-9144-1-1.html

调用matlab自带的函数“tabulate”统计
例1】统计数值型数组中各元素出现的频数、频率
 
    

>> x = [2 2 6 5 2 3 2 4 3 4 3 4 4 4 4 2 2 6 0 4 7 2 5 8 3 1 3 2 5 3 6 2 3 5 4 3 1 4 2 2 2 3 1 5 2 6 3 4 1 2 5]; >> tabulate(x(:)) Value Count Percent 0 1 1.96% 1 4 7.84% 2 14 27.45% 3 10 19.61% 4 10 19.61% 5 6 11.76% 6 4 7.84% 7 1 1.96% 8 1 1.96%

例2 】统计字符串中各字符出现的频数、频率
 
    

>> x = ['If x is a numeric array, TABLE is a numeric matrix.']'; >> tabulate(x) Value Count Percent I 1 2.44% f 1 2.44% x 2 4.88% i 5 12.20% s 2 4.88% a 5 12.20% n 2 4.88% u 2 4.88% m 3 7.32% e 2 4.88% r 5 12.20% c 2 4.88% y 1 2.44% , 1 2.44% T 1 2.44% A 1 2.44% B 1 2.44% L 1 2.44% E 1 2.44% t 1 2.44% . 1 2.44%

例3 】统计字符型数组中各行元素出现的频数、频率
 
    

>> x = ['崔家峰';'孙乃喆';'安立群';'王洪武';'王玉杰';'高纯静';'崔家峰'; '叶 鹏';'关泽满';'谢中华';'王**';'孙乃喆';'崔家峰';'谢中华']; >> tabulate(x) Value Count Percent 崔家峰 3 21.43% 孙乃喆 2 14.29% 安立群 1 7.14% 王洪武 1 7.14% 王玉杰 1 7.14% 高纯静 1 7.14% 1 7.14% 关泽满 1 7.14% 谢中华 2 14.29% 王** 1 7.14%

阅读(6453) |  评论(1)

你可能感兴趣的:(Math)