0
0
MATLABdata~20 mins

Converting between types in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of MATLAB Type Conversion
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of converting numeric array to logical
What is the output of this MATLAB code?
a = [0 1 2 -3 0];
b = logical(a);
disp(b);
MATLAB
a = [0 1 2 -3 0];
b = logical(a);
disp(b);
A[0 0 0 0 0]
B[false true true true false]
C[false 1 1 1 false]
D[0 1 1 1 0]
Attempts:
2 left
💡 Hint
Logical conversion treats zero as false and nonzero as true.
Predict Output
intermediate
2:00remaining
Result of char to double conversion
What is the output of this MATLAB code?
c = 'MATLAB';
d = double(c);
disp(d);
MATLAB
c = 'MATLAB';
d = double(c);
disp(d);
A[77 65 84 76 65 66]
B['M' 'A' 'T' 'L' 'A' 'B']
C[109 97 116 108 97 98]
D[0 0 0 0 0 0]
Attempts:
2 left
💡 Hint
double converts characters to their ASCII numeric codes.
Predict Output
advanced
2:00remaining
Output of converting numeric to string and back
What is the value of variable y after running this MATLAB code?
x = 123.45;
s = string(x);
y = double(s);
MATLAB
x = 123.45;
s = string(x);
y = double(s);
ANaN
BError: Cannot convert string to double directly
C[49 50 51 46 52 53]
D123.45
Attempts:
2 left
💡 Hint
double applied to a string array returns NaN if string is not numeric array.
Predict Output
advanced
2:00remaining
Effect of converting logical array to double
What is the output of this MATLAB code?
l = [true false true];
d = double(l);
disp(d);
MATLAB
l = [true false true];
d = double(l);
disp(d);
A[2 1 2]
B[true false true]
C[0 0 0]
D[1 0 1]
Attempts:
2 left
💡 Hint
Logical true converts to 1, false to 0 when cast to double.
Predict Output
expert
2:00remaining
Output of converting cell array of mixed types to numeric array
What error or output does this MATLAB code produce?
c = {1, '2', 3};
a = cell2mat(c);
MATLAB
c = {1, '2', 3};
a = cell2mat(c);
A[1 2 3]
B[1 '2' 3]
CError: cell2mat cannot convert cell array with mixed types
D[1 0 3]
Attempts:
2 left
💡 Hint
cell2mat requires all cells to be numeric arrays of compatible sizes.