ismembertol second output specification

5 ビュー (過去 30 日間)
Bruno Luong
Bruno Luong 2023 年 8 月 21 日
編集済み: Bruno Luong 2023 年 8 月 22 日
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 日
編集済み: 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 日
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');

カテゴリ

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