Bird
0
0

What is the output of the following MATLAB code?

medium📝 Predict Output Q13 of 15
MATLAB - String Handling
What is the output of the following MATLAB code?
str = 'abracadabra';
pos = strfind(str, 'ra');
disp(pos);
A[3 10]
B[2 9]
C[4 11]
D[]
Step-by-Step Solution
Solution:
  1. Step 1: Identify substring positions in 'abracadabra'

    Look for 'ra' in the string: 'abracadabra'. The substring 'ra' starts at index 3 and 10.
  2. Step 2: Confirm output of strfind

    strfind returns starting indices of matches, so output is [3 10].
  3. Final Answer:

    [3 10] -> Option A
  4. Quick Check:

    Positions of 'ra' = [3 10] [OK]
Quick Trick: Count string indices carefully for strfind output [OK]
Common Mistakes:
  • Counting indices starting at 0 instead of 1
  • Confusing substring length with position
  • Expecting logical output instead of indices

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes