您的位置:首页 > 编程语言 > MATLAB

MATLAB sort函数应用——求一个矩阵前L个最大值及其在矩阵中的位置

2014-03-06 09:22 351 查看
For vectors, sort(X) sorts the elements of X in ascending order.

For matrices, sort(X) sorts each column of X in ascending order.

For N-D arrays, sort(X) sorts the along the first non-singleton dimension of X. When X is a cell array of strings, sort(X) sorts the strings in ASCII dictionary order.

对于一个矩阵X,[M,N]=sort(X)返回矩阵每一列排序后的结果及每个排序后元素在原矩阵中列的位置。

dist_measured =

0 1.0000 1.7321 2.0000 1.7321 1.0000 1.0000

0 0 1.0000 1.7321 2.0000 1.7321 1.0000

0 0 0 1.0000 1.7321 2.0000 1.0000

0 0 0 0 1.0000 1.7321 1.0000

0 0 0 0 0 1.0000 1.0000

0 0 0 0 0 0 0

[x y]=sort(dist_measured)

x =

0 0 0 0 0 0 0

0 0 0 0 0 1.0000 1.0000

0 0 0 0 1.0000 1.0000 1.0000

0 0 0 1.0000 1.7321 1.7321 1.0000

0 0 1.0000 1.7321 1.7321 1.7321 1.0000

0 1.0000 1.7321 2.0000 2.0000 2.0000 1.0000

y =

1 2 3 4 5 6 6

2 3 4 5 6 1 1

3 4 5 6 4 5 2

4 5 6 3 1 2 3

5 6 2 2 3 4 4

6 1 1 1 2 3 5

由此可见直接求最大点坐标不合适,(find函数只会返回某一个值得坐标)

因此可用如下方法[x,y]=sort(dist_measured(:)),该方法返回dist_measured矩阵的向量形式并且排序,这样可得出最大的前L个值及其在向量中的位置,经过转换可求得在原矩阵中的坐标
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐