Real quick one, passing through a matrix backwards or just flip it.
Show older comments
During a for or while loop I would like to start at the back of the matrix and cycle to the beginning. Or do I just flip it using a(end:-1:1,:) or flipud(a). I understand flipud but can you briefly explain the syntax for a(end:-1:1,:).
Thanks AD
Accepted Answer
More Answers (1)
Walter Roberson
on 27 Oct 2011
Cycling the loop backwards
for K=size(A,1):-1:1
can be quite efficient, and seldom requires more memory than working forwards (indeed, moving forwards can be less efficient if you have not preallocated a matrix.)
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!