Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a character array named greeting with the text 'Hello'.
MATLAB
greeting = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes creates a string array, not a character array.
Not using quotes at all causes an error.
✗ Incorrect
In MATLAB, character arrays are created using single quotes. So 'Hello' creates a character array.
2fill in blank
mediumComplete the code to concatenate two character arrays a and b into c.
MATLAB
a = 'Hi'; b = ' there'; c = a[1]b;
Attempts:
3 left
💡 Hint
Common Mistakes
Using plus (+) operator which works for strings but not character arrays.
Using commas which cause syntax errors.
✗ Incorrect
In MATLAB, concatenating character arrays is done by placing them inside square brackets [].
3fill in blank
hardFix the error in the code to convert a string s to a character array.
MATLAB
s = "Hello"; chars = [1](s);
Attempts:
3 left
💡 Hint
Common Mistakes
Using string() which converts character arrays to strings, not the other way.
Using cellstr() which converts to cell arrays.
✗ Incorrect
The char() function converts a string to a character array in MATLAB.
4fill in blank
hardFill both blanks to create a character array of the first 3 letters of s.
MATLAB
s = 'MATLAB'; firstThree = s([1]:[2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as start index which is invalid in MATLAB.
Using 4 as end index which gets 4 letters instead of 3.
✗ Incorrect
To get the first 3 letters, slice from index 1 to 3 in MATLAB.
5fill in blank
hardFill all three blanks to create a character array with uppercase letters from s and then find its length.
MATLAB
s = 'matlab'; upperS = [1](s); len = [2](upperS); disp([3]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using numel() instead of length() which also works but here length() is expected.
Trying to display upperS instead of the length variable.
✗ Incorrect
Use upper() to convert to uppercase, length() to get length, and display the variable len.
