two panel histogram in matlab

main.m
% Example data
data1 = randn(1000,1);
data2 = 2 + randn(1000,1);

% Create histogram subplot
figure
subplot(1,2,1)
histogram(data1)
title('Data 1')

subplot(1,2,2)
histogram(data2)
title('Data 2')
197 chars
14 lines

Explanation:

  • subplot(1,2,1) creates a subplot with 1 row, 2 columns and sets the current axis to the first panel of the subplot
  • histogram(data1) adds a histogram to the first panel using data1 as the input
  • title('Data 1') adds a title to the first panel
  • subplot(1,2,2) creates a subplot with 1 row, 2 columns and sets the current axis to the second panel of the subplot
  • histogram(data2) adds a histogram to the second panel using data2 as the input
  • title('Data 2') adds a title to the second panel

gistlibby LogSnag