MATLAB 2D and 3D Plotting 2 — Questions and Answers
Question 1: Which function adds a color bar legend to a surface plot in MATLAB?
- colorbar (Correct answer)
- colormap
- colorlegend
- caxis
Correct answer: colorbar
colorbar displays a color scale bar alongside the current axes to indicate the data values mapped to colors.
Question 2: What does the 'hold on' command do in MATLAB plotting?
- Freezes axis limits permanently
- Allows subsequent plots to be added to the current figure without erasing existing content (Correct answer)
- Saves the current figure to disk
- Pauses execution until the user closes the figure
Correct answer: Allows subsequent plots to be added to the current figure without erasing existing content
'hold on' retains the current plot and its properties so that new plots added with subsequent commands are overlaid on the same axes.
Question 3: In MATLAB, which property of a plot line specifies its thickness?
- Width
- LineWidth (Correct answer)
- Thickness
- StrokeWidth
Correct answer: LineWidth
The LineWidth property controls the width of plot lines and can be set as a name-value pair in plotting functions like plot().
Question 4: Which MATLAB function creates a bar chart?
- histogram
- stem
- bar (Correct answer)
- stairs
Correct answer: bar
The bar() function creates a 2D bar chart where each data value is represented as a vertical bar.
Question 5: How do you set the x-axis limits to range from 0 to 10 in MATLAB?
- xlim([0 10]) (Correct answer)
- xrange(0, 10)
- set(gca, 'x', [0 10])
- axis x [0 10]
Correct answer: xlim([0 10])
xlim([min max]) sets the x-axis display limits of the current axes to the specified range.
Question 6: Which MATLAB function is used to add a text label to a specific point on a plot?
- label
- annotate
- text (Correct answer)
- addtext
Correct answer: text
The text(x, y, 'string') function places a text annotation at the coordinate (x, y) on the current axes.
Question 7: What is the effect of calling 'axis equal' in MATLAB?
- Makes all axis tick marks equally spaced
- Sets the x and y axis to have the same data range
- Makes the data units equal in length along each axis so circles appear round (Correct answer)
- Equalizes the font size of all axis labels
Correct answer: Makes the data units equal in length along each axis so circles appear round
'axis equal' sets the aspect ratio so that data units are the same length along both axes, preventing distortion of shapes like circles.
Which function adds a color bar legend to a surface plot in MATLAB?