I am having problems plotting two or more boxes with boxplot() and using legend().
In short: boxplot() seems to have seven entries (the box itself, the quartils, the median and so on...). So, when handing over two strings as entries to legend(), the first one is representing the first box. But the second entry is not representing the second box but one of those parameters of the first box (i guess). When creating a legend() with eight entries, the last one is the one representing the second box.
(the behaviour of boxplot() seems to be different on my systems: At WinOS the first entry is a real rectangle, while the next six are lines. In Linux, all of the entries are lines, so this problem is somehow hidden).
Here's an example, where the third entry should be a dashed line to show the issue.
The question is how to access the second box to pass it to legend() and leave out the six other parameters of the first box.
data1 = randn(100, 1);
data2 = randn(100, 1) + 3;
figure;
b=boxplot({data1, data2})
hold on;
p1=plot([0 2.5],[2 2],'--')
legend({'data1','data2','line'})