Binary Vector Frequency of 1's

18 vues (au cours des 30 derniers jours)
ata bulu
ata bulu le 10 Déc 2018
Commenté : ata bulu le 13 Déc 2018
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 ?

Réponse acceptée

James Tursa
James Tursa le 10 Déc 2018
Modifié(e) : James Tursa le 10 Déc 2018
b = your row vector of 1's and 0's
result = cumsum(b) ./ (1:numel(b));
  1 commentaire
ata bulu
ata bulu le 13 Déc 2018
thanks a lot it worked. :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by