MATLAB Answers

0

Array inside an Array

Asked by Dimitrios Adam on 4 Sep 2019
Latest activity Edited by Rik
on 4 Sep 2019
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

  0 Comments

Sign in to comment.

1 Answer

Rik
Answer by Rik
on 4 Sep 2019
Edited by Rik
on 4 Sep 2019
 Accepted Answer

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 Comments

Sign in to comment.