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

后端 未结 2 687
长发绾君心
长发绾君心 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:41

    Just use hold all instead of hold on and put the legend labels in a cell array

    hold all
    for i=1:8
        .
        .
        .
        plot(b,r);
    
        Leg{i} = ['qho-',num2str(i)];    
    
    end
    legend(Leg)
    

    See this question for example: Sparse matrix plot matlab


    NOTE:

    From Matlab R2014b onward, hold on has been modified to act like hold all, i.e. change the colours of the plots each time one is plotted. The docs state that the hold all syntax will be removed in future releases.

提交回复
热议问题