grouping data by value
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
wesso Dadoyan
el 4 de Ag. de 2015
Comentada: Chanaka Keerthisinghe
el 7 de Jun. de 2018
I have a vector of data X that I want to divide into 10 different groups depending on the values. i,e the highest 10% together, then the lower 10% together etc.... How can I create another vector that assigns numbers to such groups. For example highest 10% should have a value of 1, then the lower 10% a value of 2 , ... then the lowest 10% a value of 10. I used :
DecileThresholds= quantile(X,(1:9)/10);
to find the points that separates the categories but I don't want to write a loop to categorize them. I thought that matlab probably has a function that automatically and elegantly give me the category number. Thanks
2 comentarios
Image Analyst
el 4 de Ag. de 2015
It's not clear to me. Let's say you have a normal distribution with 1000 elements with values going from 0 to 10. Do you want 10 arrays where each array has 100 (which is 10% of 1000) elements? Or do you want 10 arrays where each array can have a different number of elements, because the number of elements in the range 500-600 will be more than the number with values in the range 0-100?
Respuesta aceptada
Más respuestas (1)
Azzi Abdelmalek
el 4 de Ag. de 2015
A=rand(1,106);
n=numel(A);
[b,idx]=sort(A);
m=round(n/10);
p=n-m*9;
ii=repmat(1:9,m,1);
jj=[ii(:) ;10*ones(p,1)];
out=accumarray(jj,b',[],@(x) {x});
celldisp(out)
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!