最近元素 MATLAB
我想查找 x=0:0.1:pi/2
中与给定数字 z=0.65
最近的元素的索引。 我已经这样做了,但我想要更好的东西: [C,I]=min(abs(xz))
。 I
是最近元素的索引。
I want to find the index of the nearest element in x=0:0.1:pi/2
to a given number z=0.65
.
I did already this, but I want something better:[C,I]=min(abs(x-z))
.I
is the index of the nearest element.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[C, I] = min(abs(xz))
是我会做的 - 我想不出对此有何改进。[~, I] = min(abs(xz))
将允许您不创建不必要的变量C
(如果您认为这是一种改进)。[C, I] = min(abs(x-z))
is what I would do - I can't think of an improvement on that.[~, I] = min(abs(x-z))
would allow you to not create an unnecessary variableC
, if you regard that as an improvement.