Shot #1(沿每个 3D 页面/切片中的列排序)
%// Get size of A
[m,n,r] = size(A)
%// Sort A along each column and get the corresponding sorting indices
[sortedA,idx] = sort(A)
%// Get the corresponding sorting indices for B and get the new B with them
idxB = bsxfun(@plus,bsxfun(@plus,idx,[0:n-1]*m),permute([0:r-1]*m*n,[1 3 2]))
newB = B(idxB)
Shot #2(对每个 3D 页面/切片中的所有元素进行排序)
%// Get size of A
[m,n,r] = size(A)
%// Reshape A into a 2D array and then sort it, and
%// also get the corresponding sorting indices
[sortedA,idx] = sort(reshape(A,[],r))
%// Get corresponding sorting indices for B, index into B with it,
%// reshape it and have the desired re-arranged B
idxB = bsxfun(@plus,idx,[0:r-1]*m*n)
newB = reshape(B(idxB),size(B))