Array inside an Array

1 回表示 (過去 30 日間)
Dimitrios Adam
Dimitrios Adam 2019 年 9 月 4 日
編集済み: Rik 2019 年 9 月 4 日
if i have one array smaller than another
expample. D=[0 1 1 2 3 4] and d=[1 2 3] and i want to find if the D vector has inside the d array also to return the position of the start of d vector for example in this case the position is 3

採用された回答

Rik
Rik 2019 年 9 月 4 日
編集済み: Rik 2019 年 9 月 4 日
If you have only positive integers, you can use an undocumented feature of strfind:
D=[0 1 1 2 3 4];d=[1 2 3];
strfind(D,d) % returns 3
If you have also other values, you can use third output of unique to convert your values into positive integers. If you're using GNU Octave you will have to cast to char to make this work (in which case only 0-255 values are likely to work).

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by