Index a small matrix in a larger matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Grace Caldwell
am 27 Mär. 2015
Beantwortet: Star Strider
am 27 Mär. 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 Kommentare
Akzeptierte Antwort
Star Strider
am 27 Mär. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!