Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to obtain ORIGINAL columnar indexes of top 3% values.

1 回表示 (過去 30 日間)
Keller Burkholder
Keller Burkholder 2019 年 2 月 8 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I need to obtain the top 3% of values from each column of an array, along with their respective indexes. I've sorted and selected the top 3% of values, and this portion of the code works, but I'm unsure of how to obtain the index of these values BEFORE they are sorted.
x = [1 3 5; 1 23 9; 123 34 75]; % Create Data
[rows,columns] = size(x); %Define rows, columns
for q = 1:columns
xSort = sort(x(:,q),'descend'); % Sort Descending
top3percentx = xSort(1:ceil(length(xSort)*0.03)); % Desired Output (top 3%)
end

回答 (3 件)

madhan ravi
madhan ravi 2019 年 2 月 8 日
編集済み: madhan ravi 2019 年 2 月 8 日

Stephen23
Stephen23 2019 年 2 月 8 日
mat = [1,3,5;1,23,9;123,34,75];
idy = 1:ceil(size(mat,1)*0.03);
for k = 1:size(mat,2)
[vec,idx] = sort(mat(:,k),'descend');
vec(idy) % top 3% values
idx(idy) % and their indices
end

Star Strider
Star Strider 2019 年 2 月 8 日
Another option, using the maxk function (introduced in R2017b):
x = rand(100, 3); % Create Data
[Top3pct,RowIdx] = maxk(x,ceil(size(x,1)*0.03))
This eliminates the (explicit) sort call, and appears to do what you want.

Community Treasure Hunt

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

Start Hunting!

Translated by