2013-09-29 116 views

回答

0

这样做,这将是一种可能的方式:

  1. 阅读基质载体中。
  2. 使用您发现的链接对向量进行排序。
  3. 将矢量存储为具有矢量值的映射作为“键”和矢量索引作为值。
  4. 当您再次使用地图读取第一个矩阵时,通过查找数字的索引填充新矩阵。
2

与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);