Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed : searching for a sequence in an array

Status
Not open for further replies.

austinpowers

Electrical
Oct 21, 2005
25
how to search for some sequence in an single dimension array,

suppose i have an array with elements
[4 3 1 6 2 5]

and i want to search whether element 1 comes before 2 or not

so i want to search for sequence 1 2
 
Replies continue below

Recommended for you

Your last two statements are inconsistent. if 1 comes before 2, that's not the same as looking for the sequence 1 2.

TTFN



 
thanks for replying ttfn


what i meant there by saying sequence is

like 1 should come before 2 ,

it doesnt matter whether there is any other element between them or not,

if i was given two elements from that sequence
[4 3 1 6 2 5]
, i should say which element comes before using matlab.


 
How about something really simple using find:


x=[4 3 1 6 2 5];

firstval=x(min(find(x==1),find(x==2)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor