how to count number of transitions
조회 수: 7 (최근 30일)
이전 댓글 표시
i want to count the number of transitions in a 1-by-n binary array.
how to do it?
n does not exceed 10.
댓글 수: 0
답변 (1개)
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);
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!