title: How to overlay histograms in matlab
body: <p>I have multiple histograms that I would like to overlay on top of each other but I don't know how to do it. I found the code below but I don't know how to modify it to run on a loop instead of just two histograms.</p>
  
  <pre><code>data1 = randn(100,1);       % data of one size
  data2 = randn(25, 1);       % data of another size!
  
  myBins = linspace(-3,3,10); % pick my own bin locations
  
  % Hists will be the same size because we set the bin locations:
  y1 = hist(data1, myBins);   
  y2 = hist(data2, myBins);
  
  % plot the results:
  figure(3);
  bar(myBins, [y1;y2]');
  title('Mixed size result');
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/ZXFha.png" alt="enter image description here"></p>
  
  <p>or what is a better way of comparing histograms if they are more than 10 or 20.</p>