Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How to obtain ORIGINAL columnar indexes of top 3% values.
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (3 件)
madhan ravi
2019 年 2 月 8 日
編集済み: madhan ravi
2019 年 2 月 8 日
https://www.mathworks.com/help/matlab/ref/sort.html#bt8nojg-1-I - see the second output of sort()
0 件のコメント
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
0 件のコメント
Star Strider
2019 年 2 月 8 日
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!