Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Searching for a vector

Subject: Searching for a vector

From: Kris zenitis

Date: 22 May, 2011 10:34:04

Message: 1 of 4

How to search for a vector inside a bigger vector and return the indexes of the beggining and the end??

Subject: Searching for a vector

From: Nasser M. Abbasi

Date: 22 May, 2011 12:21:23

Message: 2 of 4

On 5/22/2011 3:34 AM, Kris zenitis wrote:
> How to search for a vector inside a bigger vector and return
> the indexes of the beggining and the end??


may be can try ismember:

EDU>> largeA=[7 8 5 3 7]; smallA=[ 8 5 3];
EDU>> [v,I]=ismember(smallA,largeA);
EDU>> I

I =

      2 3 4

--Nasser

Subject: Searching for a vector

From: Roger Stafford

Date: 22 May, 2011 17:51:04

Message: 3 of 4

"Kris zenitis" wrote in message <iraoqs$c3v$1@newscl01ah.mathworks.com>...
> How to search for a vector inside a bigger vector and return the indexes of the beggining and the end??
- - - - - - - - -
  Let v1 be the small vector and v2 the large vector.

 n1 = length(v1);
 [~,first] = ismember(v1,hankel(v2(1:n1),v2(n1:end),'rows');
 last = first+n1-1;

Roger Stafford

Subject: Searching for a vector

From: ImageAnalyst

Date: 22 May, 2011 19:45:39

Message: 4 of 4

On May 22, 6:34 am, "Kris zenitis" <gio.1...@hotmai.com> wrote:
> How to search for a vector inside a bigger vector and return the indexes of the beggining and the end??

-----------------------------------------
For completeness, here's yet another option:
http://www.mathworks.com/matlabcentral/fileexchange/23998-findsubmat

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us