Find the indicies of the top 250 values of a Matrix
1 view (last 30 days)
Show older comments
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 Comments
Torsten
on 5 Apr 2023
Why ? maxk returns a matrix whose columns contain the k largest elements of each column of A.
Thus the matrix has dimension 250x27471.
Accepted Answer
the cyclist
on 5 Apr 2023
Edited: the cyclist
on 5 Apr 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)
[B,I] = maxk(M(:),3, 'ComparisonMethod', 'abs')
More Answers (1)
Chunru
on 5 Apr 2023
Not very clear on what you are asking. Here is a guess.
Rho = rand(5, 6) % small matrix for illustration
[B, I] = maxk(Rho(:), 7, 'ComparisonMethod', 'abs') % top 7 of all Rho (not columnwise)
[row, col] = ind2sub(size(Rho), I);
[row col]
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!