problem with the setdiff function

조회 수: 2 (최근 30일)
alex
alex 2014년 3월 17일
댓글: alex 2014년 3월 17일
Hello!
i have a problem here
A = 2:.1:15
B=[9.4000 10.4000]
C=setdiff(A,B)
the elements 9.4000 and 10.4000 are still in the C
however,if B=[9.3000 10.3000] then the setdiff works fine,and the elements are not in the C.
any idea why this happens?
  댓글 수: 2
per isakson
per isakson 2014년 3월 17일
alex
alex 2014년 3월 17일
unfortunatelly the format hex is not working

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 17일
편집: Azzi Abdelmalek 2014년 3월 17일
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 17일
편집: Azzi Abdelmalek 2014년 3월 17일
Use some tolerance
A = 2:.1:15
B=[9.4000 10.4000 1000]
tol=0.0001
s=abs(bsxfun(@minus,A',B))<tol
[ii,jj]=find(s==1);
A(ii)=[]
alex
alex 2014년 3월 17일
thank you very much!
it works excellent!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jos (10584)
Jos (10584) 2014년 3월 17일
A = 2:.1:15
B = [9.4000 10.4000]
D = 2 ; % number of digits that should match (e.g. 1.231 = 1.229)
C = setdiff(round(A*10^D),round(B*10^D)) ./ (10^D)
  댓글 수: 1
alex
alex 2014년 3월 17일
thank you for your answer! very useful!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by