How can I find the top 5% values' index in a 3D matrix

Réponses (2)

Thorsten
Thorsten le 17 Nov 2015
Modifié(e) : Thorsten le 17 Nov 2015
X = rand(10, 10, 3); % sample data
[~, idx] = sort(X(:));
Linear indices:
idxtop5perc = idx(end-5*numel(X)/100+1:end)
Subscripts:
[i, j, k] = ind2sub(size(X), idxtop5perc);

2 commentaires

some values in x maybe same, this can solve the problem?
If you want the indices of the top 5% values where some values can be the same, you can use
u = unique(X(:));
v = u(floor(end-5*numel(u)/100));
ind = find(X >= v);

Connectez-vous pour commenter.

demodata = rand(100, 50, 20); %a 3d matrix;
[values, idx] = sort(demodata, 'descend');
%depending on what is meant by top 5%:
%5% of the population
idxpop = idx(1:ceil(end/20))
%5% of the maximum value
idxval = idx(values >= values(1)*.95)
sort your data and filter it any way you want.

Catégories

Tags

Question posée :

le 17 Nov 2015

Commenté :

le 17 Nov 2015

Community Treasure Hunt

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

Start Hunting!

Translated by