Assign rank to values in a matrix
Show older comments
Hello, I have 10*10 matrix that I want to assign a rank to each element of the matrix in descending order from 1 to 100. I know how to assign in a rank in a specific row or column using for example tiedrank but I want to assign a ranking to the whole matrix in a way that I have a 10*10 matrix at the end that represents the rank at each element corrosponding to the value from 1 to 100. Can someone please help me? I'd appreicate it. Thank you in advance.
1 Comment
MarshallSc
on 23 May 2021
Accepted Answer
More Answers (2)
YourArray = randi(100, 10, 10)
[~, idx] = sort(YourArray(:), 'descend');
rank = zeros(size(YourArray));
rank(idx) = 1:numel(YourArray)
1 Comment
MarshallSc
on 23 May 2021
Azza Hamdi
on 12 Nov 2021
0 votes
% MATRIX X
X=[73 80 75 1; 93 88 93 1; 89 91 90 1; 96 98 100 1; 73 66 70 1; 53 46 55 1; 69 74 77 1; 47 56 60 1; 87 79 90 1; 79 70 88 1; 69 70 73 1; 70 65 74 1; 93 95 91 1; 79 80 73 1; 70 73 78 1];
% Matrix Y
Y=[152; 185; 180; 196; 142; 101; 149; 115; 175; 164; 141; 141; 184; 152; 148];
% Transpose of matrix X
x = X.';
% multiply Matrix X by the tranpose
B=X*x;
% inverse of multiplication
% pinv(A) is a pseudoinverse of A. If Ax = b does not have an exact solution, then pinv(A) returns a least-squares solution.
V=pinv(B);
% V=B^(-1);
% MATRIX X
X=[73 80 75 1; 93 88 93 1; 89 91 90 1; 96 98 100 1; 73 66 70 1; 53 46 55 1; 69 74 77 1; 47 56 60 1; 87 79 90 1; 79 70 88 1; 69 70 73 1; 70 65 74 1; 93 95 91 1; 79 80 73 1; 70 73 78 1];
% Matrix Y
Y=[152; 185; 180; 196; 142; 101; 149; 115; 175; 164; 141; 141; 184; 152; 148];
% Transpose of matrix X
x = X.';
% multiply Matrix X by the tranpose
B=X*x;
% inverse of multiplication
% pinv(A) is a pseudoinverse of A. If Ax = b does not have an exact solution, then pinv(A) returns a least-squares solution.
V=pinv(B);
% V=B^(-1);
% Hat matrix
H=V*X*x;
% to find estimate parameter BETA
Q=x*V*Y;
% predicted
y=H*Y;
% Q=y./X;
% to estimate error
% unit matrix
I=eye(15,15);
% error
e1=I-H;
e=e1*Y;
% e2=Y-y;
Categories
Find more on Matrix Indexing 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!