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

Respuestas (2)

Thorsten
Thorsten el 17 de Nov. de 2015
Editada: Thorsten el 17 de Nov. de 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 comentarios

Yun Shen
Yun Shen el 17 de Nov. de 2015
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);

Iniciar sesión para comentar.

Guillaume
Guillaume el 17 de Nov. de 2015
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.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 17 de Nov. de 2015

Comentada:

el 17 de Nov. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by