Color Code Plotted Data According to Value in Un-Plotted Column

28 views (last 30 days)
Camille Woicekowski
Camille Woicekowski on 26 Sep 2020
I have a 53x3 matrix of data and I would like to plot the 2nd and 3rd columns color-coded with a colormap according to the value in the first column. The first column has 13 unique values and each unique value appears in varying frequency in the rows.
For example, the matrix
would plot six lines in three different colors, two lines (in color 1) corresponding to 100, one line (in color 2) corresponding to 101, and three lines (in color 3) corresponding to 102. Again, values in the first column would not be plotted but would appear in a legend.
What is the best way to go about doing this?

Answers (1)

Srivardhan Gadila
Srivardhan Gadila on 2 Oct 2020
Refer to the documentation of plot & legend.
Also the following code may help you (Note that you may have to make changes according to your usage):
sz = size(data);
for i = 1:sz(1)
hold on
hold off
function color = getColor(data)
switch data
case 100
color = [1 0 0];
case 101
color = [0 1 0];
case 102
color = [0 0 1];




Community Treasure Hunt

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

Start Hunting!