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)
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.