[英]MATLAB find array element and conditionally add to a constant
Given this array of angles: 给定这个角度数组:
123.5280
129.5280
129.0130
136.2960
139.1640
145.7430
148.9800
156.9080
168.3440
179.2340
3.0840
3.9720
I would like to identify those which are < 90 degrees 我想确定那些<90度
angles(angles < 90)
ans =
3.0840
3.9720
and add 180 to only those two having as a result 并将180加到结果为
123.5280
129.5280
129.0130
136.2960
139.1640
145.7430
148.9800
156.9080
168.3440
179.2340
183.0840
183.9720
How do I achieve this? 我该如何实现?
angles(angles < 90) = angles(angles < 90) + 180
The behaviour you are looking for is called (phase) unwrapping and there's a built in function unwrap
for that 您正在寻找的行为称为(阶段)解包,并且有一个内置的函数unwrap
包
res = unwrap(angles / 90 * pi) / pi * 90
Note that unwrap
works in radians and for jumps of +/-pi and not 2*pi as you request, hence I'm intentionally scaling with 90 * pi
instead of 180 * pi
. 请注意, unwrap
以弧度为单位,并且对于+/- pi而不是您要求的2 * pi跳跃,因此我特意使用90 * pi
而不是180 * pi
缩放。 Also see the discussion here . 另请参见此处的讨论。
一行解决方案:
angles=angles+(angles<90)*180;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.