Bird
Raised Fist0
MATLABdata~20 mins

Line styles, markers, and colors in MATLAB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Line Style Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this MATLAB plot command?
Consider the following MATLAB code snippet:
plot(1:5, 'r--o')

What does this command produce in terms of line style, marker, and color?
MATLAB
plot(1:5, 'r--o')
AA red solid line with square markers
BA blue solid line with circle markers
CA red dashed line with circle markers
DA green dotted line with star markers
Attempts:
2 left
💡 Hint
The string 'r--o' specifies color, line style, and marker in that order.
❓ Predict Output
intermediate
2:00remaining
What color and marker does this plot use?
Given the MATLAB command:
plot(1:3, 'g:*')

What is the color, line style, and marker used?
MATLAB
plot(1:3, 'g:*')
AGreen solid line with circle markers
BGreen dotted line with star markers
CBlue dotted line with star markers
DRed dashed line with square markers
Attempts:
2 left
💡 Hint
The order is color, line style, then marker.
❓ Predict Output
advanced
2:00remaining
What is the output of this MATLAB plot command with multiple style characters?
Analyze the MATLAB command:
plot(1:4, 'b-.s')

What line style, marker, and color does this produce?
MATLAB
plot(1:4, 'b-.s')
ABlue dash-dot line with square markers
BBlue dashed line with circle markers
CBlack dash-dot line with square markers
DBlue solid line with star markers
Attempts:
2 left
💡 Hint
Remember 'b' is blue, '-.' is dash-dot line, and 's' is square marker.
❓ Predict Output
advanced
2:00remaining
What error or output does this MATLAB plot command produce?
Consider this MATLAB command:
plot(1:5, 'r-o-')

What happens when you run this?
MATLAB
plot(1:5, 'r-o-')
APlots a red dotted line with square markers
BPlots a red solid line with circle markers
CPlots a red dashed line with circle markers
DSyntax error due to invalid line style string
Attempts:
2 left
💡 Hint
Line style strings must be in a valid order and format.
🧠 Conceptual
expert
3:00remaining
How many unique line style and marker combinations are possible with MATLAB's basic plot specifiers?
MATLAB basic plot specifiers include 7 colors (b,g,r,c,m,y,k), 7 line styles (-, --, :, -., none, ' ', ''), and 9 marker types (o, +, *, ., x, s, d, ^, v).

How many unique combinations of color, line style, and marker can be created if you must specify exactly one color, one line style, and one marker?
A315
B63
C441
D49
Attempts:
2 left
💡 Hint
Multiply the number of options for each category.

Practice

(1/5)
1. Which of the following is the correct way to plot a red dashed line with circle markers in MATLAB?
easy
A. plot(x, y, 'ro-')
B. plot(x, y, '-ro')
C. plot(x, y, 'o-r')
D. plot(x, y, 'r--o')

Solution

  1. Step 1: Understand MATLAB line style syntax

    In MATLAB, the format 'color lineStyle marker' is used inside the plot command, for example 'r--o' means red color, dashed line, and circle markers.
  2. Step 2: Match the correct order

    The correct order is color first ('r'), then line style ('--'), then marker ('o'). So 'r--o' is correct.
  3. Final Answer:

    plot(x, y, 'r--o') -> Option D
  4. Quick Check:

    Color + line style + marker = 'r--o' [OK]
Hint: Remember order: color, line style, then marker [OK]
Common Mistakes:
  • Putting marker before line style
  • Using wrong order of characters
  • Confusing color codes with markers
2. Which of the following MATLAB plot commands will produce a blue solid line with square markers?
easy
A. plot(x, y, 'b-s')
B. plot(x, y, 'sb:')
C. plot(x, y, 'b:sq')
D. plot(x, y, 'bs:')

Solution

  1. Step 1: Identify the correct syntax for blue solid line with square markers

    In MATLAB, 'b' means blue, '-' means solid line, and 's' means square marker. The order is color, line style, marker.
  2. Step 2: Check each option

    plot(x, y, 'b-s') 'b-s' correctly follows the order: blue color, solid line, square marker.
  3. Final Answer:

    plot(x, y, 'b-s') -> Option A
  4. Quick Check:

    Color + line style + marker = 'b-s' [OK]
Hint: Use 'color-lineStyle-marker' order in plot string [OK]
Common Mistakes:
  • Mixing order of marker and line style
  • Using invalid marker codes
  • Adding extra characters like 'sq'
3. What will be the color and style of the line plotted by this command?
plot(x, y, 'g:*')
medium
A. Green dotted line with star markers
B. Green solid line with star markers
C. Green dash-dot line with star markers
D. Green dashed line with star markers

Solution

  1. Step 1: Decode the plot style string 'g:*'

    'g' means green color, ':' means dotted line style, and '*' means star markers.
  2. Step 2: Combine the meanings

    The line will be green, dotted, with star markers.
  3. Final Answer:

    Green dotted line with star markers -> Option A
  4. Quick Check:

    Color = green, line style = dotted, marker = star [OK]
Hint: ':' means dotted line, '*' means star marker [OK]
Common Mistakes:
  • Confusing ':' with dash-dot line
  • Mixing marker and line style symbols
  • Assuming solid line by default
4. Identify the error in this MATLAB plot command:
plot(x, y, 'r--x-o')
medium
A. Color code 'r' is incorrect
B. Multiple markers specified, which is invalid
C. Line style '--' cannot be combined with markers
D. Missing semicolon at the end

Solution

  1. Step 1: Analyze the plot style string 'r--x-o'

    This string tries to specify two markers: 'x' and 'o', which is not allowed in MATLAB plot format.
  2. Step 2: Understand MATLAB plot style rules

    Only one marker can be specified along with one line style and one color. Multiple markers are invalid.
  3. Final Answer:

    Multiple markers specified, which is invalid -> Option B
  4. Quick Check:

    Only one marker allowed in plot style [OK]
Hint: Use only one marker symbol in plot style string [OK]
Common Mistakes:
  • Adding multiple markers in one style string
  • Ignoring MATLAB plot style syntax rules
  • Thinking semicolon affects plot style
5. You want to plot two lines on the same graph: one with a green dash-dot line and circle markers, and the other with a magenta dotted line and square markers. Which MATLAB code correctly does this?
hard
A. plot(x1, y1, 'g-.o'); plot(x2, y2, 'm:s');
B. plot(x1, y1, 'g-o.'); hold on; plot(x2, y2, 'm.s:'); hold off;
C. plot(x1, y1, 'g-.o'); hold on; plot(x2, y2, 'm:s'); hold off;
D. plot(x1, y1, 'g:o-'); hold on; plot(x2, y2, 'm-s.'); hold off;

Solution

  1. Step 1: Understand the required styles

    First line: green ('g'), dash-dot ('-.'), circle marker ('o'). Second line: magenta ('m'), dotted (':'), square marker ('s').
  2. Step 2: Check each option for correct syntax and use of 'hold on'

    plot(x1, y1, 'g-.o'); hold on; plot(x2, y2, 'm:s'); hold off; uses 'g-.o' and 'm:s' correctly and uses 'hold on' to plot both lines on the same graph.
  3. Step 3: Verify other options

    plot(x1, y1, 'g-o.'); hold on; plot(x2, y2, 'm.s:'); hold off; and D have incorrect order or invalid style strings. plot(x1, y1, 'g-.o'); plot(x2, y2, 'm:s'); misses 'hold on' so second plot overwrites first.
  4. Final Answer:

    plot(x1, y1, 'g-.o'); hold on; plot(x2, y2, 'm:s'); hold off; -> Option C
  5. Quick Check:

    Use correct style strings and 'hold on' to combine plots [OK]
Hint: Use 'hold on' to plot multiple lines with different styles [OK]
Common Mistakes:
  • Forgetting 'hold on' to keep previous plots
  • Mixing order of line style and marker
  • Using invalid style strings like 'g:o-'
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