0
0
MATLABdata~10 mins

Bar and histogram plots in MATLAB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple bar plot of the data vector.

MATLAB
data = [5, 10, 15, 20];
bar([1]);
Drag options to blanks, or click blank then click option'
Aplot
Bhistogram
Cdata
Dscatter
Attempts:
3 left
💡 Hint
Common Mistakes
Using plot instead of bar function input.
Using histogram function inside bar function.
Passing a function name instead of data.
2fill in blank
medium

Complete the code to create a histogram with 10 bins for the data vector.

MATLAB
data = randn(100,1);
histogram(data, [1]);
Drag options to blanks, or click blank then click option'
A10
B5
C20
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using too few or too many bins causing unclear histogram.
Passing a vector instead of a scalar for bins.
3fill in blank
hard

Fix the error in the code to correctly plot a bar chart with categories.

MATLAB
categories = {'A', 'B', 'C'};
values = [10, 20, 15];
bar(categorical([1]), values);
Drag options to blanks, or click blank then click option'
Avalues'
Bvalues
C1:3
Dcategories
Attempts:
3 left
💡 Hint
Common Mistakes
Using a numeric vector like 1:3, which results in default numeric labels.
Using values as the x-axis input.
4fill in blank
hard

Fill both blanks to create a histogram with 15 bins and set the face color to red.

MATLAB
data = randn(200,1);
h = histogram(data, [1]);
h.FaceColor = [2];
Drag options to blanks, or click blank then click option'
A15
B10
C'red'
D'blue'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color without quotes.
Setting bins to a wrong number.
5fill in blank
hard

Fill all three blanks to create a bar plot with custom x labels and set the bar color to green.

MATLAB
values = [3, 7, 5];
categories = {'X', 'Y', 'Z'};
bar(1:3, values, 'FaceColor', [1]);
set(gca, 'XTickLabel', [2]);
title([3]);
Drag options to blanks, or click blank then click option'
A'red'
B'green'
Ccategories
D'My Bar Plot'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color without quotes.
Passing numeric vector instead of cell array for XTickLabel.
Forgetting quotes around title string.