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

7 vues (au cours des 30 derniers jours)
Camille Woicekowski
Camille Woicekowski le 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
data=[100,4.1,3.2;100,1.9,2.4;101,3.5,2.1;102,5.4,3.2;102,7.1,8.2;102,5.3,2.3]
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?

Réponses (1)

Srivardhan Gadila
Srivardhan Gadila le 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):
data=[100,4.1,3.2;100,1.9,2.4;101,3.5,2.1;102,5.4,3.2;102,7.1,8.2;102,5.3,2.3];
sz = size(data);
figure
for i = 1:sz(1)
plot(data(i,2),data(i,3),'-o','Color',getColor(data(i,1)))
hold on
end
hold off
legend(num2str(data(:,1)))
function color = getColor(data)
switch data
case 100
color = [1 0 0];
case 101
color = [0 1 0];
case 102
color = [0 0 1];
end
end

Catégories

En savoir plus sur Orange dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by