Bird
0
0

What is the output of the following MATLAB code?

medium📝 Predict Output Q4 of 15
MATLAB - String Handling
What is the output of the following MATLAB code?
str = 'hello world';
pos = strfind(str, 'o');
A[4 7]
B[6 9]
C[5 8]
D[]
Step-by-Step Solution
Solution:
  1. Step 1: Identify positions of 'o' in 'hello world'

    Characters: h(1) e(2) l(3) l(4) o(5) space(6) w(7) o(8) r(9) l(10) d(11)
  2. Step 2: Find indices where 'o' appears

    'o' appears at positions 5 and 8.
  3. Final Answer:

    [5 8] -> Option C
  4. Quick Check:

    strfind('hello world','o') = [5 8] [OK]
Quick Trick: Count characters to find substring indices [OK]
Common Mistakes:
  • Counting from zero
  • Missing second occurrence
  • Confusing with contains output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes