Plot points with x-axis from 0 to 6, y-axis from 0 to 12, x-ticks at 0,2,4,6 and y-ticks at 0,6,12 -> Option A
Quick Check:
axis + xticks + yticks control limits and ticks [OK]
Hint: axis sets limits; xticks/yticks set tick marks [OK]
Common Mistakes:
Assuming default ticks remain after setting axis
Thinking xticks/yticks need same length as data
Confusing axis limits with tick positions
4. Identify the error in this MATLAB code snippet for setting axis limits and fix it:
plot(1:3, [5 10 15]) axis(0 3 0 20)
medium
A. Limits must be strings; use axis('0 3 0 20')
B. axis function does not set limits; use xlim and ylim instead
C. Missing square brackets around limits; should be axis([0 3 0 20])
D. No error; code runs fine
Solution
Step 1: Check axis function syntax
The axis function requires a vector input for limits, enclosed in square brackets.
Step 2: Identify missing brackets
The code uses axis(0 3 0 20) without brackets, causing syntax error.
Final Answer:
Missing square brackets around limits; should be axis([0 3 0 20]) -> Option C
Quick Check:
axis([xmin xmax ymin ymax]) needs brackets [OK]
Hint: Always use square brackets for axis limits [OK]
Common Mistakes:
Omitting brackets around axis limits
Using strings instead of numeric vectors
Confusing axis with xlim or ylim functions
5. You want to create a plot with x-axis from -5 to 5, y-axis from -10 to 10, and custom ticks every 2 units on both axes. Which MATLAB code correctly achieves this?