when the line for i = 1:a:20 is executed it uses the value of a as it is then known, which is probably 1.
You will need something like this:
i = 1;
while i<=20
idx = find(consecutiveDiff(:,1)==val(i));
a = numel(idx);
i = i + a;
end
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!