Bird
Raised Fist0
MATLABdata~20 mins

Scatter plots in MATLAB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Scatter Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Basic Scatter Plot Command
What will be the output of the following MATLAB code snippet?
MATLAB
x = 1:5;
y = [2 4 6 8 10];
scatter(x, y, 'filled')
AA scatter plot with 5 blue filled circles at points (1,2), (2,4), (3,6), (4,8), (5,10)
BA scatter plot with 5 red filled circles at points (1,2), (2,4), (3,6), (4,8), (5,10)
CA line plot connecting points (1,2), (2,4), (3,6), (4,8), (5,10)
DSyntax error due to missing marker size argument
Attempts:
2 left
💡 Hint
The 'filled' option fills the markers with the default color.
❓ Predict Output
intermediate
2:00remaining
Effect of Marker Size in Scatter Plot
What is the effect of the marker size argument in this MATLAB scatter plot code?
MATLAB
x = 1:3;
y = [3 6 9];
scatter(x, y, 100, 'r')
ASyntax error because marker size must be a vector
BPlots 3 red circles with default marker size at points (1,3), (2,6), (3,9)
CPlots 3 red circles with marker size 100 (large markers) at points (1,3), (2,6), (3,9)
DPlots 3 blue circles with marker size 100 at points (1,3), (2,6), (3,9)
Attempts:
2 left
💡 Hint
The third argument in scatter is the marker size in points squared.
🔧 Debug
advanced
2:00remaining
Identify the Error in Scatter Plot Code
What error will this MATLAB code produce when run?
MATLAB
x = 1:4;
y = [2 4 6];
scatter(x, y)
AError: Vectors x and y must be the same length
BNo error, plots 3 points ignoring extra x value
CError: Missing marker size argument
DPlots 4 points with y values repeated
Attempts:
2 left
💡 Hint
Check the length of x and y vectors.
🧠 Conceptual
advanced
2:00remaining
Understanding Color Mapping in Scatter Plots
Given the code below, what does the vector 'c' control in the scatter plot?
MATLAB
x = 1:5;
y = [5 4 3 2 1];
c = [10 20 30 40 50];
scatter(x, y, 100, c, 'filled')
colorbar
A'c' is ignored because color is set by 'filled'
B'c' controls the size of each marker
C'c' sets the transparency of each marker
D'c' controls the color of each marker based on its value, mapped to a colormap
Attempts:
2 left
💡 Hint
The fourth argument in scatter can be a vector for color data.
🚀 Application
expert
3:00remaining
Creating a Scatter Plot with Variable Marker Sizes and Colors
Which code snippet correctly creates a scatter plot with x and y coordinates, marker sizes proportional to y values, and colors mapped to x values?
Ax = 1:4; y = [10 20 30 40]; scatter(x, y, x, y, 'filled')
Bx = 1:4; y = [10 20 30 40]; scatter(x, y, y, x, 'filled')
Cx = 1:4; y = [10 20 30 40]; scatter(x, y, y, 'filled', x)
Dx = 1:4; y = [10 20 30 40]; scatter(x, y, 'filled', y, x)
Attempts:
2 left
💡 Hint
The third argument is marker size, the fourth is color data.

Practice

(1/5)
1. What does a scatter plot in MATLAB primarily show?
easy
A. A bar chart of grouped data
B. A continuous line connecting data points
C. Points representing pairs of values on an X-Y graph
D. A pie chart of category percentages

Solution

  1. Step 1: Understand scatter plot purpose

    A scatter plot shows individual points for pairs of values, usually X and Y coordinates.
  2. Step 2: Compare options to definition

    Only Points representing pairs of values on an X-Y graph describes points on an X-Y graph, which matches scatter plot behavior.
  3. Final Answer:

    Points representing pairs of values on an X-Y graph -> Option C
  4. Quick Check:

    Scatter plot = points on X-Y graph [OK]
Hint: Scatter plots show points, not lines or bars [OK]
Common Mistakes:
  • Confusing scatter plot with line plot
  • Thinking scatter plots show bars or pie slices
  • Assuming scatter plots connect points
2. Which of the following is the correct MATLAB syntax to create a scatter plot of vectors x and y?
easy
A. plot.scatter(x, y)
B. scatter(x, y)
C. scatterplot(x, y)
D. scatter x, y

Solution

  1. Step 1: Recall MATLAB scatter syntax

    The correct function to create scatter plots is scatter(x, y).
  2. Step 2: Check other options for syntax errors

    Options A, C, and D are not valid MATLAB commands for scatter plots.
  3. Final Answer:

    scatter(x, y) -> Option B
  4. Quick Check:

    scatter function syntax = scatter(x, y) [OK]
Hint: Use scatter() function with parentheses and commas [OK]
Common Mistakes:
  • Using dot notation like plot.scatter
  • Typing scatterplot instead of scatter
  • Omitting parentheses or commas
3. What will the following MATLAB code display?
x = 1:5;
y = [2 4 6 8 10];
scatter(x, y, 100, 'r', 'filled')
medium
A. A scatter plot with red filled circles sized 100 at points (1,2), (2,4), ..., (5,10)
B. A line plot connecting points from (1,2) to (5,10)
C. An error because 'filled' is not a valid option
D. A scatter plot with default size and blue color points

Solution

  1. Step 1: Understand scatter parameters

    The code uses scatter(x, y, 100, 'r', 'filled') which sets point size to 100, color red ('r'), and fills the markers.
  2. Step 2: Interpret the plot output

    The plot shows red filled circles at points (1,2), (2,4), (3,6), (4,8), and (5,10).
  3. Final Answer:

    A scatter plot with red filled circles sized 100 at points (1,2), (2,4), ..., (5,10) -> Option A
  4. Quick Check:

    scatter(x,y,100,'r','filled') = red filled circles [OK]
Hint: Size, color, and fill control marker appearance [OK]
Common Mistakes:
  • Thinking 'filled' causes error
  • Confusing scatter with line plot
  • Ignoring size and color parameters
4. Identify the error in this MATLAB code for a scatter plot:
x = 1:4;
y = [5 6 7];
scatter(x, y)
medium
A. Vectors x and y have different lengths causing an error
B. scatter requires a third argument for size
C. scatter cannot plot numeric vectors
D. No error; code runs fine

Solution

  1. Step 1: Check vector lengths

    Vector x has length 4, but y has length 3, which is invalid for scatter.
  2. Step 2: Understand scatter input requirements

    Scatter requires x and y to be the same length to plot pairs of points.
  3. Final Answer:

    Vectors x and y have different lengths causing an error -> Option A
  4. Quick Check:

    Length mismatch in x,y vectors = error [OK]
Hint: x and y must be same length for scatter [OK]
Common Mistakes:
  • Assuming scatter auto-fixes length mismatch
  • Thinking size argument is mandatory
  • Believing scatter can't plot numeric data
5. You have two groups of data points:
x1 = [1 2 3]; y1 = [4 5 6];
x2 = [1 2 3]; y2 = [7 8 9];

How can you plot both groups on the same scatter plot with different colors using filled markers and add a legend?
hard
A. plot(x1, y1, 'b'); plot(x2, y2, 'r'); legend('Group 1', 'Group 2')
B. scatter(x1, y1, 'b', 'filled'); scatter(x2, y2, 'r', 'filled'); legend('Group 1', 'Group 2')
C. scatter(x1, y1, 'b'); hold on; scatter(x2, y2, 'r'); legend('Group 1', 'Group 2')
D. scatter(x1, y1, 'b', 'filled'); hold on; scatter(x2, y2, 'r', 'filled'); legend('Group 1', 'Group 2')

Solution

  1. Step 1: Plot first group with filled blue markers

    Use scatter(x1, y1, 'b', 'filled') to plot blue filled points.
  2. Step 2: Use hold on before plotting second group

    To overlay plots, hold on keeps the first plot visible before adding the second.
  3. Step 3: Plot second group with filled red markers and add legend

    Plot second group with scatter(x2, y2, 'r', 'filled') and add legend for clarity.
  4. Final Answer:

    scatter(x1, y1, 'b', 'filled'); hold on; scatter(x2, y2, 'r', 'filled'); legend('Group 1', 'Group 2') -> Option D
  5. Quick Check:

    Use hold on to overlay scatter plots with legend [OK]
Hint: Use hold on to combine scatter plots with different colors [OK]
Common Mistakes:
  • Forgetting hold on causes second plot to overwrite first
  • Using plot instead of scatter for points
  • Omitting legend or using incorrect syntax
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard