필터 지우기
필터 지우기

grouping data by value

조회 수: 17 (최근 30일)
wesso Dadoyan
wesso Dadoyan 2015년 8월 4일
댓글: Chanaka Keerthisinghe 2018년 6월 7일
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
Image Analyst
Image Analyst 2015년 8월 4일
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?
wesso Dadoyan
wesso Dadoyan 2015년 8월 4일
I want 10 arrays where each array has a different number of observations. Assume the value range is between 1 and 100 , then the 1st array (1st group) is of observations that fall between 1 and 10, 2nd group falls between 11 and 20 etc.... the number of values between 1 and 10 could be higher than those between 11 and 20, so the number of each array elements are not the same.

댓글을 달려면 로그인하십시오.

채택된 답변

Cedric
Cedric 2015년 8월 4일
편집: Cedric 2015년 8월 4일
x = [1, 8, 2, 3, 3, 7] ; % Dummy example.
[~, binId] = histc( x, [0, 4, 10] ) ; % Bin edges: 0 --bin1-- 4 --bin2-- 10
With that you get:
binId =
1 2 1 1 1 2
Then you can group them per bin:
grouped = accumarray( binId', x, [], @(v){v} ) ;

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 4일
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)
  댓글 수: 1
wesso Dadoyan
wesso Dadoyan 2015년 8월 4일
Thanks Azzi, the groups shouldn't be of equal size. Look at my comment to the inquiry of image analyst. I hve the impression that your codes generated equal groups and the remainder went to the last group

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by