Finding the mean value for five maximum number in matrix

Hi guys, I have (1*9) matrix below, I 'd like to calculate mean value for max 5 number in this matrix can anyone help me?
Regards

 採用された回答

Star Strider
Star Strider 2015 年 1 月 20 日

1 投票

This works:
x = [20 19 1 20 21 22 4 2 1];
xs = sort(x,'descend');
max5mean = mean(xs(1:5))
produces:
max5mean =
20.4

2 件のコメント

Ali Noori
Ali Noori 2015 年 1 月 20 日
thank you Sir, it works correctly
Star Strider
Star Strider 2015 年 1 月 20 日
My pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Chad Greene
Chad Greene 2015 年 1 月 20 日
編集済み: Chad Greene 2015 年 1 月 20 日

0 投票

X_sorted = sort(X);
mean5 = mean(X_sorted(1:5),'descend');

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by