Plot different classes in different colors

I' m doing a pca and I want make a general function to plot two different classes in different colors( blue square, red circle) in the same figure and i want to use this funtion in any other experiment
Resuming: for the data above, the values of class 1 must be in different color in the class 2 in the same figure
for example
Var1 Var2 Var*n* Class
2.3 0.22 12 1
2.4 0.23 11 1
2.8 0.21 15 2
2.1 0.21 16 1
2.9 0.23 14 2
Best regards Rafael

2 件のコメント

bym
bym 2011 年 4 月 6 日
do you want to plot Var1 vs Var2, or each variable in a separate plot colored according to class?
Rafael Freire
Rafael Freire 2011 年 4 月 7 日
Var1 x Var2
Like PC1xPC2

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2011 年 4 月 6 日

1 投票

class1 = V(:,4) == 1;
plot3(V(class1,1), V(class1,2), V(class1,3), 'bs.');
hold on
plot3(V(~class1,1), V(~class1,2), V(~class1,3), 'ro.');

3 件のコメント

Rafael Freire
Rafael Freire 2011 年 4 月 7 日
編集済み: Walter Roberson 2018 年 3 月 26 日
The idea works great but i use this for plot Var1xVar2
class1=milk(:,13)==1
plot (scores(class1,1), scores(class1,2),'.r','markersize', 20);
hold on
plot (scores(~class1,1), scores(~class1,2),'^b', 'markersize', 7);
Thanks
joynjo
joynjo 2018 年 3 月 24 日
how to show different color of score in image?
Walter Roberson
Walter Roberson 2018 年 3 月 26 日
The 'b' and 'r' control color.

サインインしてコメントする。

その他の回答 (2 件)

Matt Tearle
Matt Tearle 2011 年 4 月 7 日

1 投票

gscatter doesn't do what you're looking for?
Rafael Freire
Rafael Freire 2011 年 4 月 7 日

0 投票

I done that above, but I don´t Know if its right. One it is the set that has values of 1 and 2 and another is the class that assume values of 1 and 2; in pca the plots must be visualized in two different regions that is the 2 classes and in each region has 2 set of experiments, set 1 and set 2.
set1=milk(:,12)==1;
set2=milk(:,12)==2;
class1=milk(:,13)==1;
class2=milk(:,13)==2;
setclass11=class1&set1;
setclass12=class1&set2;
setcclass21=class2&set1;
setclass22=class2&set2;
figure
hold on;
plot (scores(setclass11,1),scores(setclass11,2),'.r','markersize', 20);
plot (scores(setclass12,1),scores(setclass12,2),'.m','markersize', 20);
plot (scores(setclass21,1),scores(setclass21,2),'^b','markersize', 7);
plot (scores(setclass22,1),scores(setclass22,2),'^c','markersize', 7);
it works....but...

カテゴリ

ヘルプ センター および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by