How to I reverse the contents of this array?

60 Ansichten (letzte 30 Tage)
Blair Hall
Blair Hall am 5 Okt. 2017
Kommentiert: Steven Lord am 5 Okt. 2017
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

Akzeptierte Antwort

James Tursa
James Tursa am 5 Okt. 2017
Bearbeitet: James Tursa am 5 Okt. 2017
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)

Weitere Antworten (1)

Image Analyst
Image Analyst am 5 Okt. 2017
You can use flipud() or fliplr().
mileMarkers = fliplr(mileMarkers);
  1 Kommentar
Steven Lord
Steven Lord am 5 Okt. 2017
If you're using release R2013b or later, you can use flip.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by