0
0
MATLABdata~10 mins

Converting between types in MATLAB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert the number 5 to a string.

MATLAB
str_num = [1](5);
Drag options to blanks, or click blank then click option'
Anum2str
Bint2str
Cstring
Dchar
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'char' which converts numbers to characters but not strings.
Using 'string' which is for string arrays, not simple conversion here.
2fill in blank
medium

Complete the code to convert the string '123' to a number.

MATLAB
num_val = [1]('123');
Drag options to blanks, or click blank then click option'
Astring
Bnum2str
Cstr2num
Dint2str
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'num2str' which converts numbers to strings, not the other way.
Using 'string' which converts to string arrays.
3fill in blank
hard

Fix the error in converting the number 65 to a character.

MATLAB
char_val = [1](65);
Drag options to blanks, or click blank then click option'
Aint2str
Bnum2str
Cstring
Dchar
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'num2str' which converts numbers to strings, not characters.
Using 'string' which creates string arrays.
4fill in blank
hard

Fill both blanks to convert the string '45' to a double and then back to a string.

MATLAB
num_val = [1]('45');
str_val = [2](num_val);
Drag options to blanks, or click blank then click option'
Astr2double
Bnum2str
Cstr2num
Dchar
Attempts:
3 left
💡 Hint
Common Mistakes
Using str2num instead of str2double which is more precise.
Using char which is for characters, not numbers.
5fill in blank
hard

Fill all three blanks to convert the number 50 to a character, then to a string, and finally back to a number.

MATLAB
char_val = [1](50);
str_val = [2](char_val);
num_val = [3](str_val);
Drag options to blanks, or click blank then click option'
Achar
Bstring
Cstr2double
Dnum2str
Attempts:
3 left
💡 Hint
Common Mistakes
Using num2str instead of string for character to string conversion.
Using str2num instead of str2double for string to number conversion.