Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' for comparison.
Using '~=' which means not equal.
✗ Incorrect
In MATLAB, == is used to compare if two values are equal.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which means less than.
Using '==' which means equal.
✗ Incorrect
The operator > checks if the left value is greater than the right value.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '~='.
Using '==' which means equal.
✗ Incorrect
The operator ~= means 'not equal' in MATLAB.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '>=' for the lower bound.
Using '<' instead of '<=' for the upper bound.
✗ Incorrect
Use >= to check if z is at least 1, and <= to check if z is at most 10.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers directly as field names.
Using '>' instead of '<' for comparison.
✗ Incorrect
We use num2str(nums(i)) as the field name, check if nums(i) < 5, and convert i to string for display.