How can i group some vectors by the last value ?

2 ビュー (過去 30 日間)
Christoph Meyer
Christoph Meyer 2018 年 5 月 21 日
編集済み: Majid Farzaneh 2018 年 5 月 21 日
hey, I am really new in Matlab so please be gentle :) I have this matrix:
data = [-3 1 0;
-3 3 1;
-2 1 0;
-2 4 1;
-1 3 1;
-1 4 1;
2 2 0;
2 4 1;
3 2 0;
4 1 0;];
and I want to draw them in a 2D axis using
gscatter(data(:,1),data(:,2)
All points with 0 should be red colored and all points with 1 should be blue colored.
I know that I can use "gscatter" with "group" for that but I don't know how to group that data.
Thanks for your answers Cheers Christoph

採用された回答

Majid Farzaneh
Majid Farzaneh 2018 年 5 月 21 日
Hi, it's all you want:
data = [-3 1 0;
-3 3 1;
-2 1 0;
-2 4 1;
-1 3 1;
-1 4 1;
2 2 0;
2 4 1;
3 2 0;
4 1 0;];
group=data(:,3);
gscatter(data(:,1),data(:,2),group,'rb','xo')
  3 件のコメント
Majid Farzaneh
Majid Farzaneh 2018 年 5 月 21 日
編集済み: Majid Farzaneh 2018 年 5 月 21 日
'rb' means first group will be 'red' and second group will be 'blue'. 'xo' means first group points will be 'x' and the seconds will be 'o'.
you can change them if you want. good luck
Majid Farzaneh
Majid Farzaneh 2018 年 5 月 21 日
編集済み: Majid Farzaneh 2018 年 5 月 21 日
You're welcome :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by