Finding top and bottom 10% of data

조회 수: 82 (최근 30일)
Brian DeCicco
Brian DeCicco 2021년 10월 11일
답변: Star Strider 2021년 10월 12일
Hello, I have a 1240x1 matrix of data and I wish to find the positions which contain the top 10% and the bottom 10% of the data (i.e. I shoud have 124 identified data points for the top 10% and 124 identified data points for the bottom 10%). Then, I would like to be able to create a new matrix containing just the top 10% data points and another matrix containing just the bottom 10% data points. Any assistance on how I can code this up would be greatly appreciated!
  댓글 수: 1
Image Analyst
Image Analyst 2021년 10월 11일
편집: Image Analyst 2021년 10월 11일
Is your data sorted, or can the top and bottom 10% of the data be scattered anywhere around in your vector? Is the 10% defined by the number of points,
percent10 = round(0.1 * numel(vector)) % 12 elements
, or is it defined by the values
percent10 = min(vec) + 0.1 * (max(vec) - min(vec));
percent90 = min(vec) + 0.9 * (max(vec) - min(vec));
which could be any number of elements? How many elements do you want to find? 12 or some variable number depending on the values?
Or do you want the 10% and 90% points defined by the CDF of the values?

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

답변 (2개)

David Hill
David Hill 2021년 10월 11일
편집: David Hill 2021년 10월 11일
n=round(.1*numuel(yourMatrix));
[~,idx]=sort(yourMatrix);
bottom=yourMatrix(idx(1:n));
top=yourMatrix(idx(end-*n+1:end));

Star Strider
Star Strider 2021년 10월 12일
If the Statistics and Machine Learning Toolbox is available, use the prctile function —
x = randn(1,20) % Create Vector
x = 1×20
-0.2063 0.3344 -0.8348 0.8107 0.4755 -1.2662 1.0489 0.1802 -1.0196 0.2353 0.2951 1.1735 1.2379 0.6631 -1.2150 -0.4980 0.5590 0.6799 -0.2000 -1.0986
v = prctile(x, [10,90]) % Determine 10th, 90th Percentiles
v = 1×2
-1.1568 1.1112
x10 = find(x<=v(1)) % Indices Of ELements At Or Below 10th Percentile
x10 = 1×2
6 15
x90 = find(x>=v(2)) % Indices Of ELements At Or Above 90th Percentile
x90 = 1×2
12 13
.

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by