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 日
Try
format hex
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 Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by