0
0
MATLABdata~20 mins

Type conversion functions in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Type Conversion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of converting string to double and back
What is the output of this MATLAB code?
MATLAB
x = '123.45';
y = str2double(x);
z = num2str(y);
disp(z);
A123.45
B'123.45'
CError: Conversion failed
D12345
Attempts:
2 left
💡 Hint
str2double converts string to number, num2str converts number back to string.
Predict Output
intermediate
2:00remaining
Result of logical to double conversion
What is the output of this MATLAB code?
MATLAB
a = true;
b = double(a);
disp(b);
Atrue
B1
C0
DError: Cannot convert logical to double
Attempts:
2 left
💡 Hint
Logical true converts to 1 as a double.
Predict Output
advanced
2:00remaining
Output of converting numeric array to char
What is the output of this MATLAB code?
MATLAB
nums = [65 66 67];
chars = char(nums);
disp(chars);
AABC
B[65 66 67]
CError: Cannot convert numeric array to char
Dabc
Attempts:
2 left
💡 Hint
char converts numeric ASCII codes to characters.
Predict Output
advanced
2:00remaining
Result of converting cell array of strings to numeric array
What is the output of this MATLAB code?
MATLAB
c = {'1', '2', '3'};
n = str2double(c);
disp(n);
A{1, 2, 3}
BError: Cannot convert cell array to numeric array
C[1 2 3]
D["1" "2" "3"]
Attempts:
2 left
💡 Hint
str2double converts each string in the cell array to a number.
Predict Output
expert
2:00remaining
Output of converting mixed numeric types to single precision
What is the output of this MATLAB code?
MATLAB
a = int16(1000);
b = double(a);
c = single(b);
disp(class(c));
Adouble
BError: Invalid conversion
Cint16
Dsingle
Attempts:
2 left
💡 Hint
int16 to double to single changes the class accordingly.