![]() |
确定向量中每个唯一元素的出现次数
如何确定MATLAB向量中值的相对频率?
vector = [ 2 2 2 2 1 1 1 2 2 1 1 1 2 2 2 2 1 2 ]; 哪个函数将返回每个唯一元素的出现次数? [B]回答:[/B] 您可以将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] ,这是唯一元素的相对频率。这将适用于整数和浮点数。 [url=https://stackoverflow.com/questions/5385651]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:11。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.