标签: sorting matlab vectorization
可能重复: Sort a matrix with another matrix
给定两个相同大小的矩阵A和B,我想在第二维(行)上对A进行排序,并对矩阵B应用相同的排序。是否可以对当前代码进行矢量化?
r = 10; c = 4; A = rand(r,c); B = reshape(1:r*c,c,r)'; % can be any random matrix' [A,order] = sort(A,2); for i=1:r B(i,:) = B(i,order(i,:)); end