How to link subgroup data points together in a plot?

I have matrix A like the below. The first column is the group number.
% GroupNo, X, Y
1, x1, y1
1, x2, y2
1, x3, y3
2, x4, y4
2, x5, y5
It's very important I plot them together like the below:
h = plot(A(:,2), A(:,3),'ro');
My question is how do I link all the data points in Group 1, Group 2, ..., respectively? I could have unknow number of groups.
When I say "link", I mean, to plot using "o-", instead of "o'.
Thanks

 Respuesta aceptada

darova
darova el 17 de Abr. de 2020
What about this?
hold on
A1 = unique(A(:,1));
cmark = {'o' '*' '.'};
for i = 1:numel(A1)
ix = A(:,1)==A1(i);
h(i) = plot(A(ix,2),A(ix,3),...
'marker',cmark{randi(3,1)},...
'color',rand(1,3));
end

6 comentarios

Or maybe scatter
scatter(A(:,2),A(:,3),[],A(:,1),'fill')
darova
darova el 17 de Abr. de 2020
Don't like scatter. It's very slow
Leon
Leon el 19 de Abr. de 2020
Many thanks, Everyone!
darova
darova el 19 de Abr. de 2020
Many thanks to me only. It was me. Im the only one here
Leon
Leon el 19 de Abr. de 2020
hehe :-)
Really appreciate your big help. The code works like a miracle!
darova
darova el 19 de Abr. de 2020
you are welcome

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2020a

Etiquetas

Preguntada:

el 16 de Abr. de 2020

Comentada:

el 19 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by