Array Search

Let's search the cell array and find the index. This simple example will help to find the index in cell array of large size.

names={'Hilda' 'Helen' 'Ada'; 'Matthew' 'Jenny' 'Justin'; 'Agnes' 'Merlin' 'Mark';}

names = 

    'Hilda'      'Helen'     'Ada'   
    'Matthew'    'Jenny'     'Justin'
    'Agnes'      'Merlin'    'Mark'  

I need to know whether the name 'Justin' exists in this cell array

find(strcmp(names,'Justin')==1)

ans =

     8

Let me retrieve the name 'Justin'  , using the index

names{8}

ans =

Justin


No comments:

Post a Comment