# How to plot 11 curves with colors more than the 7 pre-defined 'y' colors?

1 view (last 30 days)
I am trying to plot 22 different curves divided into two sets. 11 curves correspond to measured data and the other 11 correspond to simulation data. The different curves correspond to different positions, and each plot line in the script below describes a certain position and plots the measured and simulated data for this specific position. For the measured data I am using a complete line and for the simulated data I am using a dashed line. That works fine for the first 7 plots, as long as I can use Matlab's 'y' colors. But as soon as I try to bring my own colors and describe them with a RGB vector I get the foolowing error in Matlab: "Vectors must be the same length" or "invalid data argument". Anybody has an idea how to plot the last 8 curves using my RGB colors and plotting in dashed and complete lines, in a similar manner as I plot the ones with the 'y' code?
color1=1/255*[102, 0, 51];
color2=1/255*[25, 51, 0];
color3=1/255*[102, 0, 102];
color4=1/255*[0, 102, 102];
figure
plot(rpm,P03,'-g+',rpm,OC_1,'--g+','LineWidth',3)
hold on
plot(rpm,P51,'-k+',rpm,OF_1,'--k+','LineWidth',3)
hold on
plot(rpm,P04,'-r+',rpm,MP_1,'--r+','LineWidth',3)
hold on
plot(rpm,P17,'-b+',rpm,FP_1,'--b+','LineWidth',3)
hold on
plot(rpm,P12,'-y+',rpm,TP_1,'--y+','LineWidth',3)
hold on
plot(rpm,P24,'-m+',rpm,IC_1,'--m+','LineWidth',3)
hold on
plot(rpm,P16,'-c+',rpm,EC_1,'--c+','LineWidth',3)
hold on
plot(rpm,P05,'Color',color1,'-'rpm,OR,'Color',color1,'--','LineWidth',3)
hold on
plot(rpm,P09,'Color',color2,'-',rpm,PCE,,'Color',color2,'--','LineWidth',3)
hold on
plot(rpm,P13,'Color',color3,'-',rpm,BFH,'Color',color3,'--','LineWidth',3)
hold on
plot(rpm,P39,'Color',color4,'-',rpm,VVT,'Color',color4,'--','LineWidth',3)
hold on

Voss on 14 May 2022
Edited: Voss on 14 May 2022
When you use Name,Value argument pairs such as 'Color',color1, they must be the last arguments in the call to plot, and they apply to all lines plotted in that call.
For example:
% x, y,linespec, x, y,linespec, Name,Value
plot([0 1],[2 3], '-c+',[0 1],[3 4], '--c+','LineWidth',3);
hold on
% x, y,linespec, x, y,linespec, Name, Value, Name,Value
plot([0 1],[5 6], '-',[0 1],[7 8], '--','Color',1/255*[102,0,51],'LineWidth',3);
Also, you don't need to use hold on more than once, in order to plot a sequence of lines like this.
Christian Tsobanoglou on 14 May 2022
Thank you! Appreciate it the tips.

R2020b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!