MATLAB Answers

Index a small matrix in a larger matrix

11 views (last 30 days)
I have larger vector and I need to find if my smaller vector is located inside the larger vector.
A=[2,3,4,1,2,3,4,1,1,2]
x=[1,2]
ismember only returns true wherever it finds either 1 or 2 in the large matrix and I'd rather have a user defined function than ismember.

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 27 Mar 2015
As strange as it may seem, strfind works here:
A=[2,3,4,1,2,3,4,1,1,2];
x=[1,2];
start_index = strfind(A,x)
produces:
start_index =
4 9
The ‘start_index’ assignment are the start indices of all occurrences of ‘x’ in ‘A’.

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags

No tags entered yet.