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!