Consider this MATLAB code snippet. What will it print?
x = 5; if x > 3 disp('Greater than 3') else disp('Less or equal to 3') end
Check the condition x > 3 and what disp does.
The variable x is 5, which is greater than 3, so the if block runs and prints 'Greater than 3'.
Look at this MATLAB code. What will it display?
for i = 1:3 if mod(i,2) == 0 disp('Even') else disp('Odd') end end
Remember mod(i,2) gives remainder when dividing by 2.
For i=1, remainder is 1 (odd), for i=2 remainder 0 (even), for i=3 remainder 1 (odd). So output is 'Odd', 'Even', 'Odd'.
Analyze this MATLAB code and select the output it produces.
score = 75; if score >= 90 disp('Grade A') elseif score >= 80 disp('Grade B') elseif score >= 70 disp('Grade C') else disp('Grade F') end
Check which condition matches the value 75 first.
75 is not >= 90 or 80 but is >= 70, so 'Grade C' is printed.
What error will this MATLAB code cause when run?
x = 10; if x > 5 disp('Big') else disp('Small')
Check if all control blocks are properly closed.
The if statement is missing the end keyword, causing a syntax error.
Which statement best explains why control flow is essential in MATLAB programming?
Think about how programs decide what to do next.
Control flow structures like if-else and loops let the program choose paths and repeat tasks, guiding the logic step-by-step.