Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski 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
Joined
Oct 21, 2005
Messages
25
Location
US
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
 
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)))
 
thanks for that somptingguy

that was really helpful

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top