121. How to reverse an array or character string#

topic: Arrays

Note

This tip is a draft1.

Write

v = v(size(v):1:-1)

to reverse a 1-D array v with lower bound 1, otherwise

v = v(ubound(v):lbound(v):-1)

v(::-1) is a zero-size array unless size(v) = 1. A character string can be reversed with the function shown.



1

From the perspective of FortranTip Browser, “draft” means that it hasn’t been edited for formatting, hasn’t had corresponding Fortran programs added, the text content hasn’t been enhanced, etc. Draft texts are extracted from the corresponding Tweet using the Twitter API.