MATLAB 2D and 3D Plotting 3 — Questions and Answers
Question 1: Which MATLAB function creates a filled contour plot?
- contour
- contourf (Correct answer)
- surf
- pcolor
Correct answer: contourf
contourf() creates a contour plot with filled regions between contour lines, using color to indicate value ranges.
Question 2: What does the 'subplot(2,3,4)' command do in MATLAB?
- Creates a 2x3 grid and activates the 4th panel (second row, first column) (Correct answer)
- Creates 4 subplots in a 2x3 arrangement
- Divides the figure into 2 rows and 3 columns and selects the subplot at position (2,3)
- Creates a subplot with 2 rows, 3 columns, and 4 plots per cell
Correct answer: Creates a 2x3 grid and activates the 4th panel (second row, first column)
subplot(m,n,p) divides the figure into an m-by-n grid and makes the p-th subplot the active one, counting left to right, top to bottom.
Question 3: Which function would you use to create a 3D scatter plot in MATLAB?
- scatter
- plot3
- scatter3 (Correct answer)
- points3
Correct answer: scatter3
scatter3(x,y,z) plots data as 3D markers at the coordinates specified by x, y, and z vectors.
Question 4: In MATLAB, what does the format string 'r--' specify in a plot command?
- Red solid line
- Red dashed line (Correct answer)
- Right-aligned double line
- Reduced dash style
Correct answer: Red dashed line
In the format string 'r--', 'r' specifies the color red and '--' specifies a dashed line style.
Question 5: Which MATLAB function returns a handle to the current axes?
- gcf
- gca (Correct answer)
- gco
- get
Correct answer: gca
gca() (Get Current Axes) returns the handle to the current axes object, which can then be used to modify axes properties.
Question 6: What is the purpose of the 'meshgrid' function before creating a 3D surface plot?
- It generates a mesh of random points for Monte Carlo simulation
- It creates 2D grid matrices of x and y coordinates needed for evaluating z = f(x,y) (Correct answer)
- It applies a mesh texture to an existing surface
- It validates that x and y vectors have the same length
Correct answer: It creates 2D grid matrices of x and y coordinates needed for evaluating z = f(x,y)
meshgrid(x,y) transforms coordinate vectors into 2D arrays so that every (x,y) combination can be used to compute z values for surface plots.
Question 7: Which MATLAB command changes the current figure's background color to white?
- set(gcf, 'Color', 'white') (Correct answer)
- figure('Background', 'w')
- bgcolor('white')
- set(gca, 'FaceColor', 'white')
Correct answer: set(gcf, 'Color', 'white')
set(gcf, 'Color', 'white') sets the Color property of the current figure (gcf) to white.
Which MATLAB function creates a filled contour plot?