Find the indicies of the top 250 values of a Matrix

조회 수: 3 (최근 30일)
Emma Davis
Emma Davis 2023년 4월 5일
댓글: Emma Davis 2023년 4월 5일
I performed a spearman correlation analysis that produced a Rho variable. The size of the Rho variable is:
sizeRho = size(Rho) = [983, 27471]
Now, I am trying to find the the indicies for the top 250 values of Rho.
Here is some of what I have tried:
sizeRho = size (Rho);
top = maxk(Rho,250);
[B,I] = maxk(Rho,250, 'ComparisonMethod', 'abs');
[top, ixt, jxt] = prctile(Rho, [90])
top = prctile(Rho, [99])
largest_vals = maxk(Rho(:), 250);
[largest_vals, indicies_t] = maxk(Rho(:), 250);
Any help and/or advice would be greatly appreciated. Thank you.
  댓글 수: 4
Torsten
Torsten 2023년 4월 5일
Why ? maxk returns a matrix whose columns contain the k largest elements of each column of A.
Thus the matrix has dimension 250x27471.
Emma Davis
Emma Davis 2023년 4월 5일
Yes. I believe I was using the wrong function by using maxk, which is why I also tried using the prctile function. I did not want the 250 largest elements of each column, but rather the 250 largest elements of the entire matrix. I hope this is clearer now.

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

채택된 답변

the cyclist
the cyclist 2023년 4월 5일
편집: the cyclist 2023년 4월 5일
[Sorry if you saw the incorrect solution I posted and then deleted.]
If you want the max values and indices for the matrix overall (rather than each column), you need this syntax:
[B,I] = maxk(Rho(:),250, 'ComparisonMethod', 'abs');
Note the use of Rho(:) as an input, rather than just Rho.
The output I has the linear indices into M.
For example
M = magic(4)
M = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
[B,I] = maxk(M(:),3, 'ComparisonMethod', 'abs')
B = 3×1
16 15 14
I = 3×1
1 12 8

추가 답변 (1개)

Chunru
Chunru 2023년 4월 5일
Not very clear on what you are asking. Here is a guess.
Rho = rand(5, 6) % small matrix for illustration
Rho = 5×6
0.6787 0.1810 0.3615 0.8210 0.5301 0.1768 0.6672 0.1126 0.0277 0.1434 0.8380 0.4849 0.4192 0.4177 0.3058 0.5544 0.7236 0.3155 0.7835 0.1233 0.4060 0.2886 0.9057 0.2207 0.4596 0.8407 0.9688 0.6253 0.7939 0.7684
[B, I] = maxk(Rho(:), 7, 'ComparisonMethod', 'abs') % top 7 of all Rho (not columnwise)
B = 7×1
0.9688 0.9057 0.8407 0.8380 0.8210 0.7939 0.7835
I = 7×1
15 24 10 22 16 25 4
[row, col] = ind2sub(size(Rho), I);
[row col]
ans = 7×2
5 3 4 5 5 2 2 5 1 4 5 5 4 1
  댓글 수: 1
Emma Davis
Emma Davis 2023년 4월 5일
This is perfect! Thank you so much! I apologize that my question was not clearer.

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

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by