说,如果我为某个矩阵A
执行此操作:
[sorted,inds] = sort(A,1,'descend')
如何对此矩阵进行反向排序?
我需要这样的东西: http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#7
有什么想法吗?
谢谢
答案 0 :(得分:2)
.gradle
使A = [8 4 6 8;3 2 5 6;9 3 4 5];
[sorted,inds] = sort(A,1,'descend')
B = NaN(size(A));
B(bsxfun(@plus, inds, 0:size(A,1):numel(A)-1)) = sorted;
等于B
。
诀窍是A
应该被解释为列索引。您需要转换为线性索引,这可以通过inds
轻松完成。