在 matlab/octave 中查找不在数组中的值
我在 matlab/octave 中有两个数组,计算 a1 并给出 a2 。如何创建第三个数组 a3 比较 a1 和 a2 并显示 a1 中缺少的值?
a1=[1,4,5,8,13]
a2=[1,2,3,4,5,6,7,8,9,10,11,12,13]
a3=[3,6,7,9,10,11,12]
如果a1=[1,4,5,8.6,13]
,这也适用于浮点数,或者我必须将 a1 只转换为整数。
谢谢
I have two arrays in matlab/octave a1 is calculated and a2 is given. How can I create a 3rd array
a3 that compares a1 to a2 and shows the values that are missing in a1?
a1=[1,4,5,8,13]
a2=[1,2,3,4,5,6,7,8,9,10,11,12,13]
a3=[3,6,7,9,10,11,12]
Also can this work for a floating point number say if a1=[1,4,5,8.6,13]
or would I have to convert a1 to integers only.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
setdiff
返回 1 的元素不在另一个数组中的数组。这适用于浮点值,但需要相等。setdiff
returns the elements of one array that aren't in another. This will work with floating-point values, but requires equality.浮点数可能很棘手。要使上述代码与它们一起使用,请检查
min(deltas) > 0.001
(或者考虑到输入数字的精度,一个合适的非常小的值)。有关详细信息,请参阅此处< /a>Floating point numbers can be tricky. To get the above code to work with them, check
min(deltas) > 0.001
(or a suitable very small value given the precision of your input numbers). For more information, see here