90% Percentile of Matrix

조회 수: 94 (최근 30일)
Jonathan Moorman
Jonathan Moorman 2020년 8월 17일
댓글: Star Strider 2020년 9월 3일
Hi! I am trying to find a way to calculate the 90% percentile of a matrix (1,n) . I provide an example below, and the value I would need to find is 0.292. (Note the matrix will changes in length). How could this be done?
[0.289, 0.254, 0.287, 0.292, 0.289, 0.267, 0.289, 0.304, 0.284, 0.282]

채택된 답변

Star Strider
Star Strider 2020년 8월 17일
Here are two possibilities, the second of which gives you the exact value in your Question:
v = [0.289, 0.254, 0.287, 0.292, 0.289, 0.267, 0.289, 0.304, 0.284, 0.282];
Out1 = prctile(v, 90)
Out2 = interp1(linspace(1/numel(v),1,numel(v)), sort(v), 0.9)
producing:
Out1 =
0.2980
Out2 =
0.2920
.
  댓글 수: 6
Jonathan Moorman
Jonathan Moorman 2020년 9월 3일
Working great again. Thanks!
Star Strider
Star Strider 2020년 9월 3일
As always, my pleasure!

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

추가 답변 (1개)

jonas
jonas 2020년 8월 17일
There is probably a one-liner for this, but I guess you could use
A = [0.289, 0.254, 0.287, 0.292, 0.289, 0.267, 0.289, 0.304, 0.284, 0.282];
B = sort(A);
id = round(numel(A).*0.9)
B(id)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by