intersect with a confidence interval?
显示 更早的评论
Hi,
Let's assume I have array a=[1.2345,1.4,1.2] and b=[1.2344,1.4,1.3]...
is there any quick way to define that if the array members have a difference less than 0.0001 they should appear in the intersection? (in this example intersect(a,b)=[1.2345,1.4])
thanks
回答(1 个)
Star Strider
2015-1-19
The intersect function doesn’t allow tolerances.
You can ‘sort of’ get around that by making your own function to truncate the numbers to a specific precision, then use intersect:
a=[1.2345,1.4,1.2];
b=[1.2344,1.4,1.3];
floorn = @(x,n) floor(x.*10^n)/10^n;
c = intersect(floorn(a,3), floorn(b,3))
If you choose to have intersect return the indices, you can then recover the original numbers from the intersection:
[c,ia,ib] = intersect(floorn(a,3), floorn(b,3));
result = a(ia)
produces:
result =
1.2345 1.4
although b(ib) would return the corresponding values in ‘b’, [1.2344 1.4]. That will be your choice.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!