Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

getnameidx

Find name in list

Syntax

nameidx = getnameidx(list, name)

Arguments

list

Cell array of name character vectors.

name

Character vector or cell array of name character vectors.

Description

nameidx = getnameidx(list, name) finds the occurrence of a name or set of names in a list. It returns an index (order number) indicating where the specified names are located within the list. If name is not found, nameidx returns 0.

If name is a cell array of names, getnameidx returns a vector containing the indices (order number) of the name character vectors within list. If none of the names in the name cell array is in list, it returns zero. If some of the names in name are not found, the indices for these names are zeros.

getnameidx finds only the first occurrence of the name in the list of names. This function is meant to be used on a list of unique names (character vectors) only. It does not find multiple occurrences of a name or a list of names within list.

Examples

Given

poultry = {'duck', 'chicken'}
animals = {'duck', 'cow', 'sheep', 'horse', 'chicken'}
nameidx = getnameidx(animals, poultry)
ans =
    1   5

Given

poultry = {'duck', 'goose', 'chicken'}
animals = {'duck', 'cow', 'sheep', 'horse', 'chicken'}
nameidx = getnameidx(animals, poultry)
ans =
    1  0  5

Related Examples

See Also

|

Introduced before R2006a

Was this topic helpful?