MATLAB: Requesting legend output changes legend behavior

legendlegend colorslegend output

In Matlab R2015b (64bit on Windows 7), the following two bits of code cause different legends to be displayed:
figure;
scatter(1:100,sin((1:100)/50*pi));
hold on;
scatter(1:100,cos((1:100)/50*pi));
legend('sin','cos');
figure;
scatter(1:100,sin((1:100)/50*pi));
hold on;
scatter(1:100,cos((1:100)/50*pi));
[eg,i,p,s] = legend('sin','cos');
The first line displays a legend with two entries having the same color (the "last" one) and the second line displays a legend having two different colors. Can somebody explain this? Surely, requesting output parameters should not have an effect on the legend itself, or should it?

Best Answer

Known bug that affects scatter; there is a fix
Related Question