MATLAB RGB Triplet

Ammar Ali Apr 29, 2021
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.

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.

Author: Ammar Ali
Ammar Ali avatar Ammar Ali avatar

Hello! I am Ammar Ali, a programmer here to learn from experience, people, and docs, and create interesting and useful programming content. I mostly create content about Python, Matlab, and Microcontrollers like Arduino and PIC.

LinkedIn Facebook

Related Article - MATLAB Plot