Matlab legend colors don't match lines
问题 Not sure what is going wrong here. I created a minimal example below: clear steps = 1:6; labels = cell(length(steps),1); xvals = 1:10; fig = figure(1); ax = axes('parent',fig); hold on for ii=1:length(steps) s=steps(ii); yvals = zeros(length(xvals)) + ii; labels{ii} = ['gain = ' num2str(s)]; plot(ax,xvals,yvals); end legend(ax, labels); hold off And the result on my system is: With less lines it can even put colors in the legend that aren't even on the plot. What is happening?! 回答1: