Bird
0
0

Which of the following MATLAB statements correctly concatenates the strings 'Data' and '123'?

easy📝 Syntax Q12 of 15
MATLAB - String Handling
Which of the following MATLAB statements correctly concatenates the strings 'Data' and '123'?
Astr = 'Data' + '123';
Bstr = strcat('Data', 123);
Cstr = ['Data' '123'];
Dstr = 'Data' & '123';
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for string concatenation

    In MATLAB, concatenation uses square brackets [ ] for character arrays or strings.
  2. Step 2: Evaluate each option

    str = ['Data' '123']; uses ['Data' '123'] which correctly joins the two strings. str = 'Data' + '123'; uses + which is invalid. str = strcat('Data', 123); uses strcat but passes a number without converting it to string. str = 'Data' & '123'; uses & which is invalid.
  3. Final Answer:

    str = ['Data' '123']; -> Option C
  4. Quick Check:

    Concatenate strings with [ ] brackets [OK]
Quick Trick: Use [ ] brackets to join strings, not + or & [OK]
Common Mistakes:
  • Using + operator for strings
  • Passing numbers directly to strcat without conversion
  • Using & operator for concatenation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes