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
Star Strider 2015 年 1 月 19 日

1 投票

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.

カテゴリ

質問済み:

2015 年 1 月 19 日

回答済み:

2015 年 1 月 19 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by