How to I reverse the contents of this array?
조회 수: 61 (최근 30일)
이전 댓글 표시
I have it right for one half of the assignment (4 elements) but not the other. The second part that I have wrong is 3 elements.
function mileMarkers = ReverseArray(mileMarkers)
% mileMarkers: Row array of mile marker values
% Reverse the contents of row array mileMarkers
mileMarkers = mileMarkers(end:-1:end-3)
end
댓글 수: 0
채택된 답변
James Tursa
2017년 10월 5일
편집: James Tursa
2017년 10월 5일
For that last index, don't use end-3 since that will only work for a 4 element array. Instead, have that last index be simply 1 which will work for any size array. I.e., mileMarkers(end:-1:1)
댓글 수: 0
추가 답변 (1개)
Image Analyst
2017년 10월 5일
You can use flipud() or fliplr().
mileMarkers = fliplr(mileMarkers);
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!