# listlib::sublist

Search sublists

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

listlib::sublist(list1, list2, <index>, <Consecutive>)

## Description

listlib::sublist(list1, list2) determines, whether the list list1 contains another list list2.

With listlib::sublist the position of the first appearance of a list in another list can be determined.

The position that was found is returned as integer. If the given list does not contain the given sublist, the number 0 is returned.

If an index is given, the search starts at this position. There with multiple occurrence of a sublist can be determined.

With the option Consecutive, the list must contain the sublist in one piece without elements in between.

## Examples

### Example 1

The sublist is a part of the list, but not in one piece:

listlib::sublist([1, 2, 3, 4, 5, 6, 7, 8], [2, 3, 5, 6])

listlib::sublist([1, 2, 3, 4, 5, 6, 7, 8], [2, 3, 5, 6], Consecutive)

The list contains the sublist, coherent and incoherent:

listlib::sublist([1, 2, 3, 4, 5, 1, 3, 5], [1, 3, 5])

listlib::sublist([1, 2, 3, 4, 5, 1, 3, 5], [1, 3, 5], Consecutive)

### Example 2

Find the last occurrence of the sublist inside of the list:

POS:= 0:
while listlib::sublist([1, 2, 3, 1, 3, 1, 2, 3], [1, 2, 3], POS + 1) > 0 do
POS:= listlib::sublist([1, 2, 3, 1, 3, 1, 2, 3], [1, 2, 3], POS + 1)
end_while:
POS

delete POS:

## Parameters

 list1, list2 MuPAD® list index Integer that determines the first search position

## Options

 Consecutive Determines that the sublist list2 is containing coherent in list1

## Return Values

Position of the first element of the containing sublist or zero