clc;
close all;
clearvars;
workspace;
format long g;
format compact;
fontSize = 16;
x1 = normrnd(10,1,[1,1000])
x2 = gamrnd(10,1,[1,1000])
x3 = exprnd(10,[1,1000])
minValue = min([x1,x2,x3])
maxValue = max([x1,x2,x3])
numBins = 500;
edges = linspace(minValue, maxValue, numBins);
counts1 = histcounts(x1, edges);
counts2 = histcounts(x2, edges);
counts3 = histcounts(x3, edges);
subplot(1, 2, 1);
bar(edges(1:end-1), counts1, 'FaceColor', 'r');
hold on;
bar(edges(1:end-1), counts2, 'FaceColor', 'g');
bar(edges(1:end-1), counts3, 'FaceColor', 'b');
grid on;
xlabel('Value', 'FontSize', 20)
ylabel('Count', 'FontSize', 20)
title('Bar Chart', 'FontSize', 20)
legend('x1 histogram', 'x2 histogram', 'x3 histogram');
subplot(1, 2, 2);
plot(edges(1:end-1), counts1, 'r-', 'LineWidth', 2);
hold on;
plot(edges(1:end-1), counts2, 'g-', 'LineWidth', 2);
plot(edges(1:end-1), counts3, 'b-', 'LineWidth', 2);
grid on;
xlabel('Value', 'FontSize', 20)
ylabel('Count', 'FontSize', 20)
title('Line Plot', 'FontSize', 20)
legend('x1 histogram', 'x2 histogram', 'x3 histogram');
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
Best Answer