필터 지우기
필터 지우기

how to count number of transitions

조회 수: 6 (최근 30일)
sakshi Garg
sakshi Garg 2015년 4월 16일
댓글: Star Strider 2015년 4월 16일
i want to count the number of transitions in a 1-by-n binary array.
how to do it?
n does not exceed 10.

답변 (1개)

Star Strider
Star Strider 2015년 4월 16일
If you want to count both the positive [0 1] and negative [1 0] transitions, the easiest way is likely:
A = randi([0 1], 1, 25);
T = sum(diff(A)~=0);
If you want the positive and negative transitions separately:
PT = sum(diff(A)>0);
NT = sum(diff(A)<0);
  댓글 수: 2
sakshi Garg
sakshi Garg 2015년 4월 16일
thanks a lot
Star Strider
Star Strider 2015년 4월 16일
My pleasure.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by