Can someone explain "tol" for me in ismembertol(A,B,tol) to see if I could use it in this context?
75 ビュー (過去 30 日間)
古いコメントを表示
I am working on a project, and I came accross the ismembertol function. "x" is a 61x61 double, and I want to extract numbers closest to the values in the xline vector. Can I use ismembertol(a,b,tol) for this? Is there a better way? Maybe using logical operations? What is the "tol" part, what does it do, and how can it be applied?
%if not exact match
%lets say we are given matrices x,y, and z by the map
xline = (0.0000:0.050:3.0000);
tol = eps(0.5); %idk what I'm doing here or what the purpose of this is. I saw it as an example on MathWorks
idx2 = find(ismembertol(x,xvalues,tol));
0 件のコメント
採用された回答
Steven Lord
2019 年 6 月 5 日
ismembertol(A, B) returns an array the same size as A. Each element of the output is true if the corresponding element of A is "close enough" to an element of B. The tol input argument lets you specify what constitutes "close enough".
2 件のコメント
Steven Lord
2019 年 6 月 7 日
eps represents the distance from a number to the next largest double-precision number. So eps(0.5) is what you need to add to 0.5 to get to the next larger number. It's quite small. Given the data in your xline vector, the default tolerance of 1e-12 is probably sufficient.
Let's use your sample data.
xline = (0.0000:0.050:3.0000)
While xline looks like it contains the value 1.45 it actually doesn't.
any(xline == 1.45)
If you were to display the element of xline that looks like it should be equal to 1.45 and 1.45 itself using the hex format to show the actual bits with which the data is stored, you'll see that it differs in the last bit.
>> format hex
>> [xline(30); 1.45]
ans =
3ff7333333333334
3ff7333333333333
>> format % Change back to the default display format
Using ismembertol with the default tolerance does find element 30 of xline, as the difference between it and 1.45 is smaller than the tolerance.
ismembertol(xline, 1.45, 1e-12)
xline(ismembertol(xline, 1.45, 1e-12))
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!