0
0
MATLABdata~10 mins

Why control flow directs program logic in MATLAB - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a number is positive.

MATLAB
if [1] > 0
    disp('Positive number');
end
Drag options to blanks, or click blank then click option'
Ax
Bvalue
Cnum
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the code.
2fill in blank
medium

Complete the code to execute the else block when the number is not positive.

MATLAB
if num > 0
    disp('Positive');
[1]
    disp('Not positive');
end
Drag options to blanks, or click blank then click option'
Aelseif num <= 0
Belseif
Cendif
Delse
Attempts:
3 left
💡 Hint
Common Mistakes
Using elseif without a condition.
3fill in blank
hard

Fix the error in the loop to print numbers from 1 to 5.

MATLAB
for i = 1:[1]
    disp(i);
end
Drag options to blanks, or click blank then click option'
A5
B0
C6
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 6 as the upper limit.
4fill in blank
hard

Fill both blanks to create a loop that prints even numbers from 2 to 10.

MATLAB
for num = [1]:[2]:10
    disp(num);
end
Drag options to blanks, or click blank then click option'
A2
B1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the step value, which prints all numbers.
5fill in blank
hard

Fill all three blanks to create a conditional that prints 'Even' or 'Odd' for a number.

MATLAB
if mod([1], [2]) == [3]
    disp('Even');
else
    disp('Odd');
end
Drag options to blanks, or click blank then click option'
Anum
B2
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the remainder to check for even numbers.