Index a small matrix in a larger matrix

2 ビュー (過去 30 日間)
Grace Caldwell
Grace Caldwell 2015 年 3 月 27 日
回答済み: Star Strider 2015 年 3 月 27 日
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.

採用された回答

Star Strider
Star Strider 2015 年 3 月 27 日
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 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by