フィルターのクリア

How to count no. of time state occur in sequence and then divide by sequence no.?

1 回表示 (過去 30 日間)
Ram k
Ram k 2016 年 5 月 7 日
コメント済み: Ram k 2016 年 5 月 7 日
Suppose I have a sequence 1,3,3,1,2,1,4,2,3,1,4,2,4,4,4,3,1,2,5,1 I have to count no. of times each state occur and then divide by sequence length and then take product, here 1 occur 6 times, 2 for 4, 3 for 4, 4 for 5 and 5 for 1 times occurring and sequence length is 20, so my final answer should be (6/20)*(4/20)*(4/20)*(5/20)*(1/20)=0.00014.

回答 (3 件)

Stephen23
Stephen23 2016 年 5 月 7 日
編集済み: Stephen23 2016 年 5 月 7 日
>> V = [1,3,3,1,2,1,4,2,3,1,4,2,4,4,4,3,1,2,5,1];
>> [~,~,idx] = unique(V);
>> prod(hist(idx,1:max(idx))/numel(V))
ans =
0.00015
Note:
>> (6/20)*(4/20)*(4/20)*(5/20)*(1/20)
ans =
0.00015

Andrei Bobrov
Andrei Bobrov 2016 年 5 月 7 日
a =[1,3,3,1,2,1,4,2,3,1,4,2,4,4,4,3,1,2,5,1];
[a1,~,c] = unique(a);
out = prod(accumarray(c,1)/numel(a));

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 7 日
編集済み: Azzi Abdelmalek 2016 年 5 月 7 日
v=[1,3,3,1,2,1,4,2,3,1,4,2,4,4,4,3,1,2,5,1]
out=prod(nonzeros(accumarray(v',1))/20)

カテゴリ

Help Center および File ExchangeMarkov Chain Models についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by