Efficient way to count the number of times a value changes to a particular value in an array

4 次查看(过去 30 天)
What is the best way to do the following:
count=0;
for i=2:length(x)
if x(i)==1 && x(i-1)~=1
count=count+1;
end
end

采纳的回答

the cyclist
the cyclist 2017-12-3
sum(x(2:end)==1 & x(1:end-1)~=1)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by