MATLAB: How to add color to this line of code without repeating the time variable everytime

colorMATLAB and Simulink Student Suitematlab graphssingle command

plot(time,[accLong,accVert,accLat,],'linewidth',2) % plot all

I do not want to use this version
plot(time,accLong,'r',time,accVert,'b',time,accLat,'k','linewidth',2) % plot all

Best Answer

  • Use plot handles to set the color
    t = 1:10;
    x1 = rand(size(t));
    x2 = rand(size(t));
    p = plot(t, [x1; x2]);
    p(1).color = 'r'; % color of first line
    p(2).color = 'b'; % color of second line