我需要在一个窗口中绘制 3 行。3 行取决于变量nbPoints
。问题是:图例中的线条只有一种颜色:红色。什么是解决方案?
谢谢!
hold on
nbPoints = [6 10 14];
for nb = nbPoints
interpolatiepunten = linspace(-1,1,nb);
veelterm = interpolerende_veelterm(interpolatiepunten, rungeFunctie, 'lagrange');
y = zeros(201);
index = 1;
for i = -1:0.01:1
y(index) = veelterm.val(i);
index = index + 1;
end
if (nb == 6)
color = 'r';
elseif (nb == 10)
color = 'b';
else
color = 'g';
end
plot(-1:0.01:1, y, color);
end
legend({'a', 'b', 'c'});
% legend('a', 'b', 'c'); does not work
hold off