Counting sequences for a non-parametric statistical test (sequence test or RUN test).

3 ビュー (過去 30 日間)
João
João 2023 年 1 月 15 日
回答済み: the cyclist 2023 年 1 月 15 日
I have a certain sequence of events, for example:
x=['F','Q','Q','F','F','F','F','Q','Q','F','F','Q','F','F','Q',]
I want to count how many different sequences are in the data. For example, the first 'F' is 1 sequence, the two 'Q' following is the 2nd sequence, the next four 'F' is the 3rd sequence, the next two 'Q' is the 4rd sequence, and so on... I did this:
r=0;
for i=2:length(x)
if x(i)~=x(1)
r=r+1;
end
I don't know if I comited some error elsewhere in the code, but by my analysis it's all correct. I'm just not sure if this is the best method to count sequences, because with bigger samples of data (like 100+ sequences) the "r" is always wrong. If anyone has any suggestions I would be much appreciated
  1 件のコメント
João
João 2023 年 1 月 15 日
If any part of the code is necessary for a better understanding of my problem, I can gladly post it here.

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

採用された回答

João
João 2023 年 1 月 15 日
I eventually found the answer, gonna leave it here in case someone needs it aswell.
x=['F','Q','Q','F','F','F','F','Q','Q','F','F','Q','F','F','Q',]
r=1;
for i=2:length(x)
if x(i)~=x(i-1)
r=r+1;
end
end

その他の回答 (1 件)

the cyclist
the cyclist 2023 年 1 月 15 日
I see you found and accepted a solution. An alternative would have been to download the versatile RunLength utility from the File Exchange. Then
[~, n] = RunLength(x);
numel(n)
would give the answer you needed.

カテゴリ

Help Center および File ExchangeDownloads についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by