Help with calculating median of an array without using built in function?
显示 更早的评论
A=[8 6 7 5 3 0 9]
b=sort(A)
b= 0 3 5 6 7 8 9
Now what are the next steps?
采纳的回答
更多回答(2 个)
Azzi Abdelmalek
2016-3-26
0 个投票
use n=numel(A) to get the number of element in A. If n is odd, the median will be b((n+1)/2), if n is even, try to find out.
William
2023-9-27
0 个投票
Heres a quicker way:
sortedvec = sort(vec)
l = length(sortedvec)
x = (l + 1) / 2
median = sortedvec(x)
类别
在 帮助中心 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!