Binary Vector Frequency of 1's

조회 수: 17 (최근 30일)
ata bulu
ata bulu 2018년 12월 10일
댓글: ata bulu 2018년 12월 13일
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일
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개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by