title: highlighted region in 2d line plot
body: <p>The code below highlights certain regions of a plot:   </p>
  
  <pre><code>x = 1:24;
  a = 1;
  b = 50;
  y = a + (b-1).*rand(length(x),1);
  
  plot(x,y);
  
  %find the peaks in the data and hilghlight the regions
  [pks,locs] = findpeaks(y);
  
  for i = 1:length(locs);
      h = area([locs(i)-(locs(i)/100) locs(i)+(locs(i)/100)],[max(y) max(y)]);
      set(h,'FaceColor',[.5,.5,.5]);
      set(h,'EdgeColor',[.5,.5,.5]);
      h1 = get(h,'children');
      set(h1,'FaceAlpha',0.3);
      hold on
  end
      plot(x,y,'k');
      hold off;
      axis([min(x) max(x) min(y) max(y)]);
  </code></pre>
  
  <p>The area highlighted is defined as 1% of the length of the data either side of the local maxima. I would like to alter so that the region is not precisely specified by a percentage of the data, as this will alter depending on the size of the data set. Can anyone suggest an alternative method for defining the thickness of the highlighted region? </p>