0
0
MATLABdata~10 mins

Type checking (class, isa) 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 check if variable x is of class 'double'.

MATLAB
if [1](x, 'double')
    disp('x is a double');
end
Drag options to blanks, or click blank then click option'
Aisa
Btype
Cclass
Disclass
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'isa' to check type.
2fill in blank
medium

Complete the code to get the class name of variable y.

MATLAB
typeName = [1](y);
Drag options to blanks, or click blank then click option'
Atype
Bclass
Ctypeof
Disa
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'isa' instead of 'class' to get the class name.
3fill in blank
hard

Fix the error in the code to check if z is a cell array.

MATLAB
if [1](z, 'cell')
    disp('z is a cell array');
end
Drag options to blanks, or click blank then click option'
Aclass
Bisclass
Cisa
Dtype
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'isa' for type checking.
4fill in blank
hard

Fill both blanks to create a dictionary of variable names and their classes for variables in the list.

MATLAB
vars = {'a', 'b', 'c'};
classes = containers.Map();
for i = 1:length(vars)
    varName = vars{i};
    classes(varName) = [1](eval([2]));
end
Drag options to blanks, or click blank then click option'
Aclass
BvarName
Cisa
Dvars{i}
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'isa' instead of 'class' for getting class name.
Using 'vars{i}' instead of 'varName'.
5fill in blank
hard

Fill all three blanks to check if each variable in the list is of class 'double' and store the result in a logical array.

MATLAB
vars = {x, y, z};
isDouble = false(1, length(vars));
for k = 1:length(vars)
    isDouble(k) = [1](vars[2], '[3]');
end
Drag options to blanks, or click blank then click option'
Aisa
B{k}
Cdouble
Dclass
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'isa' for checking type.
Using wrong indexing syntax.