How can I change the color of the plot in each iteration in MATLAB?

后端 未结 2 712
长发绾君心
长发绾君心 2021-01-18 20:12

The following is a part of my matlab code. As it\'s shown, I would like to plot 8 curves in one plot. But I want to make each curve with one unique color. I also want to cha

2条回答
  •  情深已故
    2021-01-18 20:48

    How about something like:

    figure, hold on
    N = 8;
    h = zeros(N,1);    %# store handle to line graphic objects
    clr = lines(N);    %# some colormap
    for i=1:N
        %# plot random data
        y = cumsum(randn(100,1));
        h(i) = plot(y, 'Color',clr(i,:));
    end
    hold off
    legend(h, num2str((1:N)','gho-%d'))    %# display legend
    

    plot

提交回复
热议问题