说,如果我这样做了一些矩阵A
:反向排序矩阵列
[sorted,inds] = sort(A,1,'descend')
我怎么做这个矩阵的逆排序?
我需要的是这样的: http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#7
任何想法?
谢谢
说,如果我这样做了一些矩阵A
:反向排序矩阵列
[sorted,inds] = sort(A,1,'descend')
我怎么做这个矩阵的逆排序?
我需要的是这样的: http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#7
任何想法?
谢谢
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
应该被解释为列索引。您需要转换为线性索引,这很容易通过bsxfun
完成。
谢谢!那我需要 –
@sof_dff很高兴它的工作。我花了一些时间来了解你想要的东西! –
说'A = [8 4 6 8; 3 2 5 6; 9 3 4 5]'。输出应该是什么? –
相同的矩阵。请参阅提供的链接 - 有一个简单的1D案例 –
相同的矩阵?那么什么都不做?请更加明确。你想要什么输出? –