Index a small matrix in a larger matrix
2 views (last 30 days)
Show older comments
Grace Caldwell
on 27 Mar 2015
Answered: Star Strider
on 27 Mar 2015
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
Accepted Answer
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!