intersect with a confidence interval?
Mostrar comentarios más antiguos
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
Respuestas (1)
Star Strider
el 19 de En. de 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.
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!