Complete the code to create a simple bar plot of the data vector.
data = [5, 10, 15, 20]; bar([1]);
The bar function in MATLAB takes the data vector as input to create a bar plot.
Complete the code to create a histogram with 10 bins for the data vector.
data = randn(100,1); histogram(data, [1]);
The second argument to histogram specifies the number of bins. Here, 10 bins are requested.
Fix the error in the code to correctly plot a bar chart with categories.
categories = {'A', 'B', 'C'};
values = [10, 20, 15];
bar(categorical([1]), values);1:3, which results in default numeric labels.values as the x-axis input.The bar function accepts a categorical array as the first input to set the x-axis labels to those categories (A, B, C).
Fill both blanks to create a histogram with 15 bins and set the face color to red.
data = randn(200,1); h = histogram(data, [1]); h.FaceColor = [2];
The first blank sets the number of bins to 15. The second blank sets the bar color to red using a string.
Fill all three blanks to create a bar plot with custom x labels and set the bar color to green.
values = [3, 7, 5]; categories = {'X', 'Y', 'Z'}; bar(1:3, values, 'FaceColor', [1]); set(gca, 'XTickLabel', [2]); title([3]);
The bar color is set to green with 'green'. The x-axis labels are set to the categories cell array. The plot title is set with a string.