Bird
0
0

What is wrong with this MATLAB code?

medium📝 Debug Q7 of 15
MATLAB - String Handling
What is wrong with this MATLAB code?
str = 'test123';
idx = regexp(str, '\\d');
disp(idx{1});
Aregexp returns numeric array, so {} indexing causes error
BPattern '\\d' is invalid
Cdisp cannot display numeric arrays
DMissing 'match' option in regexp
Step-by-Step Solution
Solution:
  1. Step 1: Understand regexp output without 'match'

    Without 'match', regexp returns numeric array of start indices.
  2. Step 2: Check indexing on numeric array

    Using {} on numeric array causes an error; () should be used instead.
  3. Final Answer:

    regexp returns numeric array, so {} indexing causes error -> Option A
  4. Quick Check:

    Use () for numeric arrays, {} for cell arrays [OK]
Quick Trick: Use () for numeric arrays, {} for cell arrays [OK]
Common Mistakes:
  • Using {} on numeric arrays
  • Expecting cell array without 'match'
  • Misunderstanding pattern validity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes