Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find middle point of a sorted array in matlab?

Tags:

matlab

i have an arry lets say

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

i want to get middle point

like B=[5]

how to do it?

like image 911
chee Avatar asked Dec 09 '22 13:12

chee


2 Answers

Try to use end to automatically obtain the index of the last entry, and use ceil to round up the half length when the length is not even

B=A(ceil(end/2))
like image 77
YYC Avatar answered Dec 23 '22 10:12

YYC


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

like image 31
Doresoom Avatar answered Dec 23 '22 11:12

Doresoom