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??

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 =
[]

 Accepted 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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!