matlab 排序点,matlab如何进行排序?

来自SORT的MATLAB文档:If A has complex entries r and s,

sort orders them according to the

following rule: r appears before s in

sort(A) if either of the following

hold:abs(r) < abs(s)

abs(r) = abs(s) and angle(r) < angle(s)

换言之,具有复杂项的数组首先基于这些项的absolute value(即复数幅度)排序,并且任何具有相同绝对值的项都基于它们的phase angles排序。在The sort order for complex numbers is

lexicographic. If both the real and

imaginary parts are non-nan then the

order is determined by the real parts

except when they are equal, in which

case the order is determined by the

imaginary parts.

换言之,具有复杂条目的数组首先根据条目的实分量进行排序,而具有相等实分量的任何条目都将基于它们的虚分量进行排序。在

编辑:

如果要在MATLAB中重现numpy行为,一种方法是使用函数SORTROWS根据数组项的real和{a7}组件创建排序索引,然后将该排序索引应用于复杂值数组:>> r = roots(q); %# Compute your roots

>> [junk,index] = sortrows([real(r) imag(r)],[1 2]); %# Sort based on real,

%# then imaginary parts

>> r = r(index) %# Apply the sort index to r

r =

0.2694 - 0.3547i

0.2694 + 0.3547i

0.3369 - 0.1564i

0.3369 + 0.1564i

0.3528

1.3579 - 1.7879i

1.3579 + 1.7879i

2.4419 - 1.1332i

2.4419 + 1.1332i

2.8344

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值