How to find the midpoint of a sorted array in matlab?

I have arry let say

A = [2 3 4 5 6 7 8 9]

I want to get the midpoint

like B = [5]

how to do it?

+4
source share
2 answers

Try using end to automatically get the index of the last record and use ceil to round half the length when the length is not equal

 B=A(ceil(end/2)) 
+12
source

The MATLAB median function will work. If you have an array with an odd number of elements, it pulls the midpoint. Otherwise, if you have an even number of points, it averages two points in the middle.

+2
source

All Articles