Backwards/Reverse in "Direct" For Loop
조회 수: 11 (최근 30일)
이전 댓글 표시
Is there a way to back backwards in a "direct" for loop?
If I had the vector A = [1 4 7 8]
How would I make it where:
for i = 1:A
increments backwards starting from 8?
댓글 수: 0
답변 (1개)
James Tursa
2018년 3월 15일
편집: James Tursa
2018년 3월 15일
for k=numel(A):-1:1
k would have the values 4, 3, 2, 1 in turn. So indexing using A(k) you would be accessing A(4), A(3), A(2), and A(1) in turn.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!