0
0
MATLABdata~10 mins

Comparison operators 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 a is equal to 10.

MATLAB
result = (a [1] 10);
Drag options to blanks, or click blank then click option'
A==
B=
C~=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' for comparison.
Using '~=' which means not equal.
2fill in blank
medium

Complete the code to check if variable x is greater than 5.

MATLAB
if x [1] 5
    disp('x is greater than 5');
end
Drag options to blanks, or click blank then click option'
A>
B==
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which means less than.
Using '==' which means equal.
3fill in blank
hard

Fix the error in the code to check if y is not equal to 0.

MATLAB
if y [1] 0
    disp('y is not zero');
end
Drag options to blanks, or click blank then click option'
A=
B==
C~=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '~='.
Using '==' which means equal.
4fill in blank
hard

Fill both blanks to create a logical expression that checks if z is between 1 and 10 (inclusive).

MATLAB
if (z [1] 1) && (z [2] 10)
    disp('z is between 1 and 10');
end
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '>=' for the lower bound.
Using '<' instead of '<=' for the upper bound.
5fill in blank
hard

Fill all three blanks to create a dictionary (struct) comprehension that stores whether each number in nums is less than 5.

MATLAB
result = struct();
for i = 1:length(nums)
    result.[1] = (nums(i) [2] 5);
end
keys = fieldnames(result);
for k = 1:length(keys)
    disp([keys{k} ': ' num2str(result.(keys{k}))]);
end
Drag options to blanks, or click blank then click option'
Anum2str(i)
B<
Cnum2str(nums(i))
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers directly as field names.
Using '>' instead of '<' for comparison.