Bird
0
0

What will be the result of this MATLAB code?

medium📝 Predict Output Q5 of 15
MATLAB - String Handling
What will be the result of this MATLAB code?
str = "MATLAB";
charArr = 'MATLAB';
disp(str(1));
disp(charArr(1));
A"M"<br>'M'
B"M"<br>"M"
C'M'<br>'M'
D'M'<br>"M"
Step-by-Step Solution
Solution:
  1. Step 1: Understand indexing on string and char array

    Indexing a string returns a string scalar with double quotes; indexing a char array returns a character with single quotes.
  2. Step 2: Check output format

    disp shows string scalars with double quotes and char arrays with single quotes.
  3. Final Answer:

    "M"
    'M'
    -> Option A
  4. Quick Check:

    String index = "M", char index = 'M' [OK]
Quick Trick: Indexing string returns string scalar; char array returns char [OK]
Common Mistakes:
  • Expecting both outputs to have same quotes
  • Confusing string scalar with char
  • Ignoring display format differences

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes