Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I have a large vector, I would like to find a set of data which is a subset of the large vector.

1 回表示 (過去 30 日間)
Yun Zhang
Yun Zhang 2019 年 2 月 18 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Any algorithm I can use to find the set of data?
  7 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 18 日
編集済み: madhan ravi 2019 年 2 月 18 日
;-) shouldn’t it be 5&6?
John D'Errico
John D'Errico 2019 年 2 月 18 日
No reason to add an answer for no reason. Moved to acomment:
"I meant the first index should be 5"

回答 (2 件)

madhan ravi
madhan ravi 2019 年 2 月 18 日
[lo,ii]=ismember(B,A);
index = ii(lo)

John D'Errico
John D'Errico 2019 年 2 月 18 日
ismember is exactly the tool to solve your problem.
A = [1 3 5 7 9 8 6 4 2];
B = [5 6];
[LIA,LOCB] = ismember(A,B)
LIA =
1×9 logical array
0 0 1 0 0 0 1 0 0
LOCB =
0 0 1 0 0 0 2 0 0
So we see that elements 3 and 7 of A are in B.
find(LIA)
ans =
3 7
And that seems to be what you are asking to learn.
  2 件のコメント
Yun Zhang
Yun Zhang 2019 年 2 月 18 日
ismember is not the right tool. The data I searched has to be in the right order. for instance, B=[5 6] and A=[ 1 3 5 7 6 5 6]. The search result has to be index 6 and 7.
madhan ravi
madhan ravi 2019 年 2 月 18 日
[r,c]=find(A.'==B);
G=findgroups(c);
index = splitapply(@max,r,G).'

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by