intersect with a confidence interval?

1 view (last 30 days)
sen_saven
sen_saven on 19 Jan 2015
Answered: Star Strider on 19 Jan 2015
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

Answers (1)

Star Strider
Star Strider on 19 Jan 2015
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.

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!