x(1:10, :) = sortrows(x(1:10, :), 1:size(x,2));
Run Code Online (Sandbox Code Playgroud)
第二个参数sortrows告诉它您要排序的列的列.所以1:size(x, 2)将依次按每列排序(按升序排列)
如果你真的想要对所有列进行完美排序(第1行到第10行)并且不保持行的完整性(即在原始中不能再找到每一行)那么(虽然这很奇怪):
for col = 1:size(B, 2)
B(1:10, col) = sort(B(1:10, col));
end
Run Code Online (Sandbox Code Playgroud)