Info

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

How do I get the index of the element that's the start of an embedded vector within a longer vector? Order mainintained.

1 回表示 (過去 30 日間)
Arthur Shapiro
Arthur Shapiro 2017 年 11 月 25 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
For example, in the containing vector (1 2 4 7 6 9 5 3 4 6 7 12 10) I would like to get the index of the first occurrence of the target (4 6 7) which is 9 not 3. I think ismember would give me 5.
  1 件のコメント
Arthur Shapiro
Arthur Shapiro 2017 年 11 月 25 日
There's a typo. I think ismember would give 3. 5 is a typo.

回答 (3 件)

Star Strider
Star Strider 2017 年 11 月 25 日
The strfind function will give you 9:
v = [1 2 4 7 6 9 5 3 4 6 7 12 10];
t = [4 6 7];
idx = strfind(v, t)
idx =
9

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 25 日
v = [1 2 4 7 6 9 5 3 4 6 7 12 10];
[~,ii] = ismember([4,6,7],hankel(v(1:end-2),v(end-2:end)),'rows');

Arthur Shapiro
Arthur Shapiro 2017 年 11 月 30 日
Thanks to both Star Strider and Andrei Bobrov for their answers

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by