MATLAB: How to count the number of consecutive values

cell arrayconsecutivecount

Hi! I have Location(1,4).loc that is a 137×19 cell array. I want to find the number of time that first column have value '674' and the consecutive value in the second column is '673'. How can I do?

Best Answer

Use strcmp, which works well for cell arrays of strings. Compare the first column to the string '674' and the second column to '673'.
x = Location(1,4).loc;
sum(strcmp(x(:,1),'674') & strcmp(x(:,2),'673'))
When I ran the above code on the data you provided, I got a result of 13.