0
0
MATLABdata~20 mins

Bar and histogram plots in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bar and Histogram Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Bar Plot with Custom Colors
What will be the color of the bars in the following MATLAB code?
MATLAB
y = [5 10 15];
bar(y, 'FaceColor', [0 0.5 0]);
ABars will be red
BBars will be green with RGB [0 0.5 0]
CBars will be blue
DBars will be black
Attempts:
2 left
💡 Hint
FaceColor property sets the bar color using RGB values between 0 and 1.
Predict Output
intermediate
2:00remaining
Histogram Bin Count Output
What is the output of the following MATLAB code?
MATLAB
data = [1 2 2 3 4 4 4 5];
h = histogram(data, 4);
disp(h.BinCounts);
A[1 2 1 4]
B[1 2 3 2]
C[2 3 2 1]
D[1 3 2 2]
Attempts:
2 left
💡 Hint
Bins are automatically spaced to cover the data range with 4 bins.
🔧 Debug
advanced
2:00remaining
Fix the Error in Bar Plot Code
The following MATLAB code produces an error. Which option fixes it so the bar plot shows correctly?
MATLAB
x = [1 2 3];
y = [4 5];
bar(x, y);
AChange y to have 3 elements: y = [4 5 6];
BUse bar(y) without x: bar(y);
CChange x to have 2 elements: x = [1 2];
DTranspose y: bar(x, y');
Attempts:
2 left
💡 Hint
x and y vectors must have the same length for bar(x,y).
📝 Syntax
advanced
2:00remaining
Identify Syntax Error in Histogram Code
Which option contains a syntax error in MATLAB histogram plotting?
Ahistogram(data, 10);
Bhistogram(data, 'BinWidth', 0.5);
Chistogram(data, 'Normalization', 'probability');
Dhistogram(data, BinWidth=0.5);
Attempts:
2 left
💡 Hint
MATLAB uses name-value pairs with quotes, not equal signs.
🚀 Application
expert
3:00remaining
Number of Bars in Grouped Bar Plot
Given the following MATLAB code, how many bars will be displayed in the plot?
MATLAB
data = [3 5 2; 4 6 1];
bar(data, 'grouped');
A2 bars
B3 bars
C6 bars
D9 bars
Attempts:
2 left
💡 Hint
Each row is a group, each column is a bar within the group.