I am trying to create a function which gives me the result of running frequency of 1's in a single generated vector of size N=100.For example if N=4, and the vector b=[0 1 0 1],then the running frequency of 1's [0 0.5 0.3333 0.5] because the frequency of 1's until the first bit is 0. How can i write this function ?

 採用された回答

James Tursa
James Tursa 2018 年 12 月 10 日
編集済み: James Tursa 2018 年 12 月 10 日

1 投票

b = your row vector of 1's and 0's
result = cumsum(b) ./ (1:numel(b));

1 件のコメント

ata bulu
ata bulu 2018 年 12 月 13 日
thanks a lot it worked. :)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumeric Types についてさらに検索

質問済み:

2018 年 12 月 10 日

コメント済み:

2018 年 12 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by