如何使用Matlab计算100000个向量中每个元素的出现次数? [英] How to calculate the number of occurrences of each element in the 100000 vectors using Matlab?

查看:222
本文介绍了如何使用Matlab计算100000个向量中每个元素的出现次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于包含40个不同数字(介于1和100之间)的100000个向量,如何计算100000个向量中每个元素的出现次数.

For 100000 vectors containing 40 different numbers between 1 and 100, how to calculate the number of occurrences of each element in the 100000 vectors.

示例:

A = [2 5 6 9]; B = [3 6 9 1]

A = [2 5 6 9]; B = [3 6 9 1]

结果应该是数字在1到10之间:[1 2 3 4 5 6 7 8 9 10,1 1 1 0 1 2 0 0 2 0]

the result should be if the numbers are between 1 and 10: [1 2 3 4 5 6 7 8 9 10, 1 1 1 0 1 2 0 0 2 0]

推荐答案

似乎您要计算所有值的直方图.
为此使用hist命令

It seems like you want to compute the histogram of all values.
Use hist command for that

n = hist( A(:), 1:100 );

这篇关于如何使用Matlab计算100000个向量中每个元素的出现次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆