开发者

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

开发者 https://www.devze.com 2023-01-21 05:33 出处:网络
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?Try to use end to automatically obtain the index of the last entry, and use ceil to

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?


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))


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消