MATLAB RGB Triplet

In this tutorial, we will discuss how to set the color of a plot using the RGB colors in MATLAB.

Setting the Color of a Plot Using the RGB Colors in MATLAB

In RGB, there are three main colors: red, green, and blue, and their value range is from 0 to 1. In MATLAB, you can define the plot color using the RGB color value. To use RGB color, you have to use the property Color in the plot function, and then after the property, you can add any values of the RGB triplet in a vector. For example, let’s add the RGB color to a line. See the code below.

clc
l = 1:100;
plot(l,l,'Color',[.1 .1 .9],'LineWidth',10)
hold on
plot(2*l,l,'Color',[.1 1 .1],'LineWidth',10)
plot(3*l,l,'Color',[1 .1 .1],'LineWidth',10)

Output:

RGB Triplet Line Color

In the above code, we plotted three lines with different RGB colors. You can set the color value from 0 to 1 according to your requirements.

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - MATLAB Plot

  • MATLAB Log Plot
  • MATLAB Plot Color Map