Challenge - 5 Problems
Type Conversion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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);Attempts:
2 left
💡 Hint
str2double converts string to number, num2str converts number back to string.
✗ Incorrect
str2double converts the string '123.45' to the numeric value 123.45. num2str converts the number back to the string '123.45'. disp prints the string without quotes.
❓ Predict Output
intermediate2:00remaining
Result of logical to double conversion
What is the output of this MATLAB code?
MATLAB
a = true; b = double(a); disp(b);
Attempts:
2 left
💡 Hint
Logical true converts to 1 as a double.
✗ Incorrect
In MATLAB, logical true converts to double 1. disp prints the numeric value 1.
❓ Predict Output
advanced2: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);
Attempts:
2 left
💡 Hint
char converts numeric ASCII codes to characters.
✗ Incorrect
65, 66, 67 are ASCII codes for 'A', 'B', 'C'. char converts them to the string 'ABC'.
❓ Predict Output
advanced2: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);Attempts:
2 left
💡 Hint
str2double converts each string in the cell array to a number.
✗ Incorrect
str2double converts each string element in the cell array to a numeric value, resulting in a numeric array [1 2 3].
❓ Predict Output
expert2: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));
Attempts:
2 left
💡 Hint
int16 to double to single changes the class accordingly.
✗ Incorrect
int16 value 1000 converts to double 1000, then to single 1000. disp(class(c)) prints 'single'.