how to count number of transitions
9 次查看(过去 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!