Find the indicies of the top 250 values of a Matrix

3 vues (au cours des 30 derniers jours)
Emma Davis
Emma Davis le 5 Avr 2023
Commenté : Emma Davis le 5 Avr 2023
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 commentaires
Torsten
Torsten le 5 Avr 2023
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 le 5 Avr 2023
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.

Connectez-vous pour commenter.

Réponse acceptée

the cyclist
the cyclist le 5 Avr 2023
Modifié(e) : the cyclist le 5 Avr 2023
[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

Plus de réponses (1)

Chunru
Chunru le 5 Avr 2023
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 commentaire
Emma Davis
Emma Davis le 5 Avr 2023
This is perfect! Thank you so much! I apologize that my question was not clearer.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by