Backwards/Reverse in "Direct" For Loop
7 ビュー (過去 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!