Challenge - 5 Problems
Numeric Types Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of mixed numeric type operations
What is the output of this MATLAB code?
a = single(5.5); b = int32(2); c = a + b; disp(class(c)); disp(c);
MATLAB
a = single(5.5); b = int32(2); c = a + b; disp(class(c)); disp(c);
Attempts:
2 left
💡 Hint
Remember MATLAB converts integer types to single or double when mixed with floating types.
✗ Incorrect
When adding a single and an int32, MATLAB converts the int32 to single before addition. The result is single type with value 7.5.
❓ Predict Output
intermediate2:00remaining
Integer division result type
What is the output of this MATLAB code?
x = int16(7); y = int16(2); z = x / y; disp(class(z)); disp(z);
MATLAB
x = int16(7); y = int16(2); z = x / y; disp(class(z)); disp(z);
Attempts:
2 left
💡 Hint
Division of integer types returns double in MATLAB.
✗ Incorrect
In MATLAB, dividing two integer types results in a double type value with floating point division.
🔧 Debug
advanced2:00remaining
Identify the error in numeric type conversion
What error does this MATLAB code produce?
a = int8(130); disp(a);
MATLAB
a = int8(130); disp(a);Attempts:
2 left
💡 Hint
int8 can only store values from -128 to 127.
✗ Incorrect
Assigning 130 to int8 wraps around due to overflow, resulting in -126 without error.
🧠 Conceptual
advanced1:30remaining
Memory size of numeric types
Which numeric type uses the least memory in MATLAB?
Attempts:
2 left
💡 Hint
Check the number of bytes each type uses.
✗ Incorrect
int8 uses 1 byte, single uses 4 bytes, int32 uses 4 bytes, double uses 8 bytes.
❓ Predict Output
expert2:30remaining
Result of mixed numeric array operations
What is the output of this MATLAB code?
A = single([1.5, 2.5]); B = int16([2, 3]); C = A .* B; disp(class(C)); disp(C);
MATLAB
A = single([1.5, 2.5]); B = int16([2, 3]); C = A .* B; disp(class(C)); disp(C);
Attempts:
2 left
💡 Hint
Element-wise multiplication with mixed types converts integers to single.
✗ Incorrect
int16 array is converted to single before multiplication, result is single array with values 3.0 and 7.5.