Bird
0
0

Given a string array strArr = ["cat", "dog", "bird"], how can you convert it to a character array where each word is a row padded with spaces?

hard📝 Application Q9 of 15
MATLAB - String Handling
Given a string array strArr = ["cat", "dog", "bird"], how can you convert it to a character array where each word is a row padded with spaces?
AcharArr = cellstr(strArr);
BcharArr = string(strArr);
CcharArr = char(strArr);
DcharArr = strArr + ' ';
Step-by-Step Solution
Solution:
  1. Step 1: Understand conversion from string array to char array

    The char() function converts string arrays to padded character arrays with each string as a row.
  2. Step 2: Check other options

    string() keeps it string, cellstr() converts to cell array of char vectors, and adding ' ' is invalid.
  3. Final Answer:

    charArr = char(strArr); -> Option C
  4. Quick Check:

    char() converts string array to padded char array [OK]
Quick Trick: Use char() to convert string array to padded char array [OK]
Common Mistakes:
  • Using string() instead of char()
  • Confusing cell arrays with char arrays
  • Trying to add spaces with + operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes