フィルターのクリア

How to find the top 10% value of the matrix?

15 ビュー (過去 30 日間)
BB
BB 2012 年 9 月 17 日
編集済み: TG 2015 年 2 月 12 日
HI,
I have a 10x10 matrix and the value is random
How do I find the the top 10% value of the matrix?
ex: if the value is 1~100,I want to get the answer is 90~100
Thanks~
  1 件のコメント
Jan
Jan 2012 年 9 月 17 日
Because I assume that this is a homework question, please explain, what you have done so far and ask a specific question about the occurring problems.

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

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 9 月 17 日
x = the_matrix;
[~,idx] = sort(x(:));
y = x(idx(1:10));

その他の回答 (1 件)

TG
TG 2015 年 2 月 12 日
編集済み: TG 2015 年 2 月 12 日
To select the top 10% of a matrix, take the total number of values and multiply by .1. Then sort and extract as in the accepted answer above:
[m n] = size(X); %where X is your matrix
TN = m*n;
TTP = TN*.1;
TTP = ceil(TTP); %round in case TN is an odd number and TTP is not an integer
(i.e. 5x5 = 25, 25/10 = 2.5)
For matrices, 'sort' sorts each column individually, so first covert the matrix into a single vector, then sort:
VX = X(:); %places values in single column
[val,ind] = sort(VX, 'descend');
y = VX(ind(1:TTP));
You can play around with the 'ind' variable and the code to locate these values in the original matrix.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by