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

1 view (last 30 days)
Christian Tsobanoglou
Christian Tsobanoglou on 14 May 2022
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];
hold on
hold on
hold on
hold on
hold on
hold on
hold on
hold on
hold on
hold on
hold on

Answers (1)

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.




Community Treasure Hunt

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

Start Hunting!