ismembertol second output specification

The command ismembertol it looks if elements of the first array belong to the second array with tolerance.
The second output argument LocB returnes which element of the second array elements of the fisrt array belong to.
In the doc it written
"LocB — Locations in B
vector | matrix | cell array
Locations in B, returned as a vector, matrix, or cell array. LocB contains the indices to the elements (or rows) in B that are found in A (within tolerance). LocB contains 0 wherever an element in A is not a member of B.
If OutputAllIndices is true, then ismembertol returns LocB as a cell array. The cell array contains the indices for all elements in B that are within tolerance of the corresponding value in A. That is, each cell in LocB corresponds to a value in A, and the values in each cell correspond to locations in B."
It doesn't however specify which of indices is selected when OutputAllIndices is false (default).
From my test it seems returns the index of the element that has smallest distance ('byRow' is off), in case of draw then it returns the first one as showed here:
[tf, iB] = ismembertol(0, [1 1 1], 2, 'DataScale', 1)
tf = logical
1
iB = 1
[tf, iB] = ismembertol(0, [1 0.5 0.2], 2, 'DataScale', 1)
tf = logical
1
iB = 3
[tf, iB] = ismembertol(0, [1 0.2 0.6], 2, 'DataScale', 1)
tf = logical
1
iB = 2
[tf, iB] = ismembertol(0, [0.2 1 0.5], 2, 'DataScale', 1)
tf = logical
1
iB = 1
[tf, iB] = ismembertol(0, [1 0.2 0.2], 2, 'DataScale', 1)
tf = logical
1
iB = 2
My questions are:
  • do I miss the specification written somewhere?
  • What happens for when 'byRow' is true?
Of course I can turn on 'OutputAllIndices' then postselect which index of B I want. But I prefer not to if the standard output already meets my need.
  • Any comment?

4 件のコメント

dpb
dpb 2023 年 8 月 21 日
The closest thing I can find is the statement in the Description section that "ismembertol is similar to ismember. Whereas ismember performs exact comparisons, ismembertol performs comparisons using a tolerance." In ismember it is documented that the returned index is the lowest of multiple matches for both with and without 'rows' option.
That is not a definitive, specification, however, just an inference that could be drawn that the same logic driving ismember was used in ismembertol. Would have to get an interpretation from Mathworks to determine for certain, however, since it's now a builtin function so can't read an m-file to see.
The 'legacy' option isn't supported with ismembertol which changes the behavior in ismember so one can also presume the alternate/prior functionality of returning last position isn't supported that would tend to reinforce using the first as your testing indicates.
Still all can do is presume or do enough testing to become convinced of the behavior empirically.
Steven Lord
Steven Lord 2023 年 8 月 21 日
The 'legacy' option isn't supported with ismembertol which changes the behavior in ismember so one can also presume the alternate/prior functionality of returning last position isn't supported that would tend to reinforce using the first as your testing indicates.
The 'legacy' option in ismember is there for backwards compatibility with releases prior to release R2013a. Since ismembertol was introduced in release R2015a, there is no "releases prior to release R2013a" with an ismembertol that the current ismembertol needs to be compatible with, so there's no 'legacy' option.
Still all can do is presume or do enough testing to become convinced of the behavior empirically.
If you haven't already, please use the form at the bottom of the ismembertol documentation page to indicate that the description of the second output is missing information you expected to find. I know for a fact that the documentation staff reviews that feedback.
dpb
dpb 2023 年 8 月 21 日
編集済み: dpb 2023 年 8 月 21 日
I was simply carrying on with the inferences that could be drawn (however tenuously) from the initial statement that "ismembertol is similar to ismember."
It does seem quite peculiar that the statement regarding which is returned in events of ties that is in ismember doc was dropped from ismembertol, however. I've almost never used it and didn't recall having noticed that prior to Bruno's pointing it out here.
Bruno Luong
Bruno Luong 2023 年 8 月 21 日
移動済み: Bruno Luong 2023 年 8 月 22 日
@Steven Lord "use the form at the bottom of the documentation page"
Do you mean clicking on the rating with "stars"? If yes I justs did. Thanks.

サインインしてコメントする。

回答 (1 件)

Bruno Luong
Bruno Luong 2023 年 8 月 22 日
編集済み: Bruno Luong 2023 年 8 月 22 日

0 投票

Here is my though on what index ismembertol returns.
It is the first index that A belong after rearrange B by dictionary like sortrows and then undo the permutation.
A = [0 0];
X = -1.25+2.5*rand(1,1000);
Y = -1.25+2.5*rand(1,1000);
B = [X(:) Y(:)];
tol = 1;
[~, idx] = ismembertol(A, B, 1, ...
'ByRows', true, 'DataScale', tol, 'OutputAllIndices', true);
idx = idx{1};
[~, idxselected] = ismembertol(A, B, 1, ...
'ByRows', true, 'DataScale', tol, 'OutputAllIndices', false);
[Bs, is] = sortrows(B);
tf = all(A >= Bs-tol & A <= Bs+tol, 2);
idx_re = sort(is(tf));
idxselected_re = is(find(tf,1));
isequal(idx, idx_re)
ans = logical
1
isequal(idxselected, idxselected_re)
ans = logical
1
Bidx = B(idx,:);
plot(A(:,1), A(:,2), '+', 'MarkerSize', 15, 'Color', 'g');
hold on
plot(B(:,1), B(:,2), '.', 'Color', 0.7+[0 0 0]);
plot(Bidx(:,1), Bidx(:,2), '.', 'Color', 'b');
plot(B(idxselected,1), B(idxselected,2), 'o', 'MarkerSize', 12, 'MarkerFaceColor', 'r');

カテゴリ

ヘルプ センター および File ExchangeData Import from MATLAB についてさらに検索

質問済み:

2023 年 8 月 21 日

編集済み:

2023 年 8 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by