Matlab for循环画图加legend

x = 1:10;
h = zeros(4);
for i = 1:4
    y = i*x;
    h(i) = plot(x,y);
    hold on
end
legend(h([1,2,3,4]),'y1','y2','y3','y4')
hold off

 

 在 for 循环中根据循环改变 legend,效果图如下

posted @ 2018-11-17 17:21  qinghev  阅读(7094)  评论(3编辑  收藏  举报