How would one reverse the order of an array using a while loop?
4 次查看(过去 30 天)
显示 更早的评论
For this homework question I am asked to write a program using the while loop that will display a given row or column vector in reverse.
0 个评论
采纳的回答
更多回答(1 个)
Walter Roberson
2016-10-30
Supposed the length of your vector is L. Then you want to copy position j to position L-j+1 in the new vector. For example, length 6, position 1 gets written to position 6-1+1 = 6; position 2 gets written to position 6-2+1 = 5, position 3 to position 6-3+1 = 4, and so on.
2 个评论
Walter Roberson
2016-10-31
In your code above,
k=length(v);
and then
L = k;
and then entry k of input corresponds to entry L-k+1 of output.
另请参阅
类别
在 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!