Matlab:如何对每个行/列,循环或公式的数据进行排序? [英] Matlab: How to sort data for each row/column, loop or formula?

查看:477
本文介绍了Matlab:如何对每个行/列,循环或公式的数据进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是数据的样子:

20.00 32.00 33.00 10.00 23.00 ......

12.00 22.00 21.00 10.00 32.00 ......

10.00 21.00 21.00 34.00 12.00 ......

......

我想分别对row(1),row(2).... row(n)进行排序.我应该写一个循环还是任何公式在这里工作?寻找解决方案,谢谢!

I would like to sort row(1), row(2)....row(n) separately. Should I write a loop or does any formula work here? Look for a solution, Thanks!

推荐答案

如果您将数据保存在Matlab矩阵中,那么sort函数就可以解决问题:

If you've got the data in a Matlab matrix then the sort function will do the trick:

A = [1,3,2
     4,1,3]

sort函数需要指定维-因为默认情况下它将对列进行排序. matlab中的数组索引从1开始,因此所需的数字为2.

The sort function needs the dimension to be specified - since by default it sorts the columns. Array indexing in matlab starts at 1, so the number required is 2.

sort(A,2) = [1,2,3
             1,3,4]

更多信息: http://www.mathworks.co.uk /help/techdoc/ref/sort.html

这篇关于Matlab:如何对每个行/列,循环或公式的数据进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆