Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 15x100 矩阵,我只想按升序对前 10 行进行排序,什么 matlab 代码可以做到这一点?
编辑:对每列的前 10 行进行排序
x(1:10, :) = sortrows(x(1:10, :), 1:size(x,2));
的第二个参数sortrows告诉它您要对哪些列进行排序。所以1:size(x, 2)将依次按每一列排序(升序)
sortrows
1:size(x, 2)
如果您实际上希望所有列都完美排序(第 1 到 10 行)并且不保持行完整性(即在原始行中不再可以找到每一行),那么(尽管这很奇怪):
for col = 1:size(B, 2) B(1:10, col) = sort(B(1:10, col)); end