MATLAB: How can i group some vectors by the last value

grouping variablesgscatterMATLAB and Simulink Student Suite

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

Best Answer

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