如何确定MATLAB向量中值的相对频率?
vector = [ 2 2 2 2 1 1 1 2 2 1 1 1 2 2 2 2 1 2 ]; 哪个函数将返回每个唯一元素的出现次数?
回答:
您可以将unique与histc结合使用以获得相对频率。
A=[1,2,3,1,2,4,2,1]; %#an example vector unqA=unique(A); 这给出了唯一元素unqA=[1,2,3,4] 。要获取发生次数,
countElA=histc(A,unqA); %# get the count of elements relFreq=countElA/numel(A); 这给出了countElA=[3,3,1,1]和relFreq=[0.3750, 0.3750, 0.1250, 0.1250] ,这是唯一元素的相对频率。这将适用于整数和浮点数。
更多&回答...