0
0
MATLABdata~5 mins

String searching (contains, strfind) in MATLAB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the contains function do in MATLAB?
The contains function checks if a string or array of strings contains a specified substring and returns a logical true or false.
Click to reveal answer
beginner
How does strfind differ from contains in MATLAB?
strfind returns the starting indices of the substring within the string, while contains returns a logical value indicating presence or absence.
Click to reveal answer
beginner
What is the output of strfind('hello world', 'o')?
It returns the indices where 'o' appears: [5 8].
Click to reveal answer
intermediate
Can contains handle arrays of strings in MATLAB?
Yes, contains can check each element of a string array or cell array of character vectors and return a logical array.
Click to reveal answer
beginner
What happens if strfind does not find the substring?
It returns an empty array [] indicating no matches.
Click to reveal answer
What does contains('apple', 'p') return?
Atrue
Bfalse
C[2 3]
D[]
What is the output of strfind('banana', 'na')?
A[3 5]
B[2 4]
C[4 6]
D[]
If strfind does not find the substring, what does it return?
A0
Bfalse
Cempty array []
DNaN
Which function returns a logical array when searching multiple strings?
Astrfind
Bcontains
Cfind
Dstrcmp
What is the difference between contains and strfind?
A<code>contains</code> returns indices, <code>strfind</code> returns logical
BBoth return logical arrays
CBoth return indices
D<code>contains</code> returns logical, <code>strfind</code> returns indices
Explain how to use contains to check if a substring exists in multiple strings.
Think about searching in a list of words.
You got /3 concepts.
    Describe what strfind returns and how it can be used to find substring positions.
    Imagine looking for where a word starts inside a sentence.
    You got /3 concepts.