Bird
0
0

Identify the error in this MATLAB code snippet:

medium📝 Debug Q6 of 15
MATLAB - String Handling
Identify the error in this MATLAB code snippet:
str = 'abc123';
matches = regexp(str, '\d+', 'match');
disp(matches{1});
ANo error; code runs correctly
BUsing curly braces to index cell array is incorrect
CPattern '\d+' is invalid in MATLAB
DMissing semicolon after regexp call
Step-by-Step Solution
Solution:
  1. Step 1: Check regexp usage

    Pattern '\\d+' is valid and 'match' returns a cell array of digit substrings.
  2. Step 2: Check cell array indexing

    Using matches{1} correctly accesses the first matched substring.
  3. Final Answer:

    No error; code runs correctly -> Option A
  4. Quick Check:

    Cell array indexing with {} is correct [OK]
Quick Trick: Use {} to access cell contents [OK]
Common Mistakes:
  • Using () instead of {}
  • Thinking pattern is invalid
  • Expecting numeric array instead of cell

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes