How to I reverse the contents of this array?
70 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Blair Hall
el 5 de Oct. de 2017
Comentada: Steven Lord
el 5 de Oct. de 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
0 comentarios
Respuesta aceptada
James Tursa
el 5 de Oct. de 2017
Editada: James Tursa
el 5 de Oct. de 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)
0 comentarios
Más respuestas (1)
Image Analyst
el 5 de Oct. de 2017
You can use flipud() or fliplr().
mileMarkers = fliplr(mileMarkers);
1 comentario
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!