Bird
0
0

Find the bug in this MATLAB code:

medium📝 Debug Q7 of 15
MATLAB - String Handling
Find the bug in this MATLAB code:
str = 'banana';
tf = contains(str, banana);
Acontains returns indices, not logical
Bcontains function is misspelled
Cstr variable is not defined
Dbanana should be in quotes
Step-by-Step Solution
Solution:
  1. Step 1: Check argument types for contains

    Substring must be a string literal or variable, here banana is undefined.
  2. Step 2: Correct usage

    banana should be in quotes: 'banana'.
  3. Final Answer:

    banana should be in quotes -> Option D
  4. Quick Check:

    Substring must be quoted string [OK]
Quick Trick: Always quote substring literals [OK]
Common Mistakes:
  • Passing undefined variables
  • Misspelling function names
  • Expecting contains to return indices

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes