Illustration of Median
When the vector is not in sorted order to start with, the median function will still return the right answer (it will sort the vector automatically). For illustration, scrambling the order of the values in the first illustration will still answer in a median value of 5.
>> median([9 4 1 5 12])
ans =
5