MATLAB: Is the loop getting skipped? I wanted las to take last array of trk with a value in it. but for some the loop seems to get skipped.. What am I doing wrong? Can someone please help?

cell arraysfor loop

tk = 1;
trk = { [1;1], [1;1], [1;1], [1;1], [0;0], [0;0], [0;0]};
las =[];
if isempty(las)
las = [0;0];
for roll = 7:1
las = cell2mat(trk{tk,roll});
if (las(1,1) ~= 0) || (las(2,1) ~= 0)
break
end
end
end
OUTPUT
las =
0
0
roll =
[]

Best Answer

for roll = 7:1
Above is equivalent to
for roll = 7:1:1
what happens when add +1 to 7 and the test for another pass in the loop?
Need the -1 step increment to walk backwards.