1
votes

I think, the question might have already been asked before. But I could not find proper answer in this forum.

Acutally, I have 2 vectors( of unequal length). I need to compare the 2 vectors. I can do it using a for loop. But it is taking a very long time.

Any obvious method which I may be missising ?

here is a small code snippet:

a=[ 1 2 3 4 5 6 7 8 1 2 3 4];
b=[ 2 3 4];

How can we compare a and b. Basically I need the index in vector a when comparison returns true.

Thanks

1
Are you asking for the index in a for where b is a subsequence of a? - Ben Hocking
Yes, I am looking for index in a, where b is a subsequence. - Kiran

1 Answers

5
votes

You can use strfind() for this (it works with doubles):

idx = strfind(a, b);

idx will contain the indices of all matches.