Finding the Probability of a Sequence of Numbers

3 ビュー (過去 30 日間)
Aragorn23
Aragorn23 2019 年 7 月 16 日
回答済み: Bruno Luong 2019 年 7 月 16 日
Hi everyone,
I have a vector with data varying from 1 to 120.
A= [10 13 10 1 111 102 10 13 7 10 112 100 14 116 102 10 14 120].
I would like to calculate, the probability' sequence of each number (e.g., probability of the number 1 be followed by the number 111; probability of the number 14 be followed by the number 116, etc ...)?
How can I do that?
Thanks.
  3 件のコメント
Adam
Adam 2019 年 7 月 16 日
Sounds like you would need to build a 120x120 matrix of occurences of each number followed by each other number (something I guess I would use a for loop to do, at least initially) and then work out probabilities from the sum of each row in the table. It's a very small sample to do any kind of probability analysis on though. I assume this is just an example and your real data is bigger?
Aragorn23
Aragorn23 2019 年 7 月 16 日
You're right, it's just a small sample.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2019 年 7 月 16 日
編集済み: Walter Roberson 2019 年 7 月 16 日
A= [10 13 10 1 111 102 10 13 7 10 112 100 14 116 102 10 14 120];
Ac = A.';
counts = accumarray([Ac(1:end-1), Ac(2:end)], 1, [120 120], [], [], true);
probs = counts ./ max(1, sum(counts,2));
[c, r, s] = find(probs.');
[r, c, s]

その他の回答 (1 件)

Bruno Luong
Bruno Luong 2019 年 7 月 16 日
N = histcounts2(A(1:end-1),A(2:end),1:121,1:121);
p = N / sum(N(:))

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by