0
A = [21 3 14;0 1 5;8 2 4]
矩阵,并且希望有一个新的矩阵
B =[9 4 8;1 2 6;7 3 5]
我发现了一个方法来创建一个矢量
http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#7
但是有矩阵的功能吗?
感谢
A = [21 3 14;0 1 5;8 2 4]
矩阵,并且希望有一个新的矩阵
B =[9 4 8;1 2 6;7 3 5]
我发现了一个方法来创建一个矢量
http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#7
但是有矩阵的功能吗?
感谢
这样做,这将是一种可能的方式:
与abhineetprasad的解决方案类似,但不需要键值结构。
您可以对矢量使用与矩阵几乎相同的方法。您只需确定A的矢量形状版本A(:)
的排序索引,并将B初始化为与A相同的维度。然后,您可以使用线性索引将其填入矩阵B中以填充行列:
% prepare matrix B with the same dimensions as A
B = zeros(size(A));
% determine sort indices of the matrix entries treated as a vector
[~, ind] = sort(A(:));
% use linear indexing by sort indices to fill vector B with ranks
B(ind) = 1 : numel(B);