Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
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.

Antworten (3)

Star Strider
Star Strider am 25 Nov. 2017
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 am 25 Nov. 2017
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 am 30 Nov. 2017
Thanks to both Star Strider and Andrei Bobrov for their answers

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by