Index a small matrix in a larger matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Grace Caldwell
el 27 de Mzo. de 2015
Respondida: Star Strider
el 27 de Mzo. de 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 comentarios
Respuesta aceptada
Star Strider
el 27 de Mzo. de 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 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!