title: Most efficient way of drawing grouped boxplot matlab
body: <p>I have 3 vectors: <code>Y=rand(1000,1)</code>, <code>X=Y-rand(1000,1)</code> and <code>ACTid=randi(6,1000,1)</code>.
  I'd like to create boxplots by groups of Y and X corresponding to their group value 1:6 (from ACTid).</p>
  
  <p>This is rather ad-hoc and looks nasty </p>
  
  <pre><code>for ii=
  dummyY(ii)={Y(ACTid==ii)};
  dummyX(ii)={X(ACTid==ii)}
  end
  </code></pre>
  
  <p>Now I have the data in a cell but can't work out how to group it in a boxplot. Any thoughts?</p>
  
  <p>I've found <code>aboxplot</code> <a href="http://alex.bikfalvi.com/research/advanced_matlab_boxplot/" rel="noreferrer">function</a> that looks like this but I don't want that, I'd like the builtin boxplot function because i'm converting it to matlab2tikz and this one doesn't do it well.</p>
  
  <p><img src="https://i.stack.imgur.com/AnEV9.png" alt="enter image description here"></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks to Oleg: we now have a grouped boxplot... but the labels are all skew-whiff.</p>
  
  <pre><code>xylabel = repmat({'Bleh','Blah'},1000,1); % need a legend instead, but doesn't appear possible
  boxplot([Y(:,end); cfu], {repmat(ACTid,2,1), xylabel(:)} ,'factorgap',10,'color','rk')
  set(gca,'xtick',1.5:3.2:50)
  set(gca,'xticklabel',{'Direct care','Housekeeping','Mealtimes','Medication','Miscellaneous','Personal care'})
  &gt;&gt; ylabel('Raw CFU counts (Y)')
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xZKGE.png" alt="enter image description here"></p>
  
  <p>How to add a legend?</p>