MATLAB: Indicating statistical significance on boxplot in matlab

boxplotMATLAB

I am plotting two boxplots with my sample data sets in matlab. I wanted to put a star sign between the boxplots indicating the statistical significance. When i draw this star, its adjusted to one corner rather than between the boxes. I am attaching the boxplot with this. Any help to solve this will be appreciated.
x1 = required_data_threhold_time_for_recruitment_gdnest;
x2 = required_data_threhold_time_for_recruitment_bdnest;
x = [x1 ;x2];
g = [ones(size(x1)); 2*ones(size(x2))];
boxplot(x,g,'Labels',{'Good nest (1 lux)','Poor nest (16 lux)'});
ylabel('Time(seconds)')
yt = get(gca, 'YTick');
axis([xlim 0 ceil(max(yt)*1.2)])
set(gca, 'Xtick', 1:3);
xt = get(gca, 'XTick');
hold on
plot(xt([2 3]), [1 1]*max(yt)*1.1, '-k', mean(xt([2 3])), max(yt)*1.15, '*k')
hold off

Best Answer

It is exactly where you plotted it, why would you expect a different result?
plot(mean(xt([2 3])), max(yt)*1.15, '*k')
so at x=2.5 (as xt = [1 2 3]) and a little bit above the maximum value of yt, which I can only assume to be 5000 (the max ytick was probably 5000 when you created yt).
The reason you are confused is probably because you are using the xticks for determining the location of the plot. What is more confusing is that your xticks extent beyond the axis limits. Basically you have a very simple problem that you try to solve in a very difficult way by involving x- and y-ticks.
If you want it between the boxes, then I can only assume that you should change to:
plot(mean(xt([1 2])), max(yt)*1.15, '*k')
...there are however a lot of assumptions going into this answer, so you may want to clarify.