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!