How to set marker groups in one plot?

3 visualizaciones (últimos 30 días)
Leon
Leon el 17 de Feb. de 2020
Comentada: Leon el 18 de Feb. de 2020
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 these data together based on the below commands, so that they can all share one ButtonDownFcn.
h1 = plot(app.Plot1, A(:,1), A(:,2), '^', 'markersize',10);
h1.ButtonDownFcn = {@FunctionSalOxy1, app, A(:,1), A(:,2)};
My question is how do I set the markers of different groups differently. For example, the index of Group 1 should be: Ind1 = A(:,1)==1;
Many thanks!

Respuesta aceptada

Joseph Cheng
Joseph Cheng el 18 de Feb. de 2020
Editada: Joseph Cheng el 18 de Feb. de 2020
Here is a snippet of code that should help you out.
%Dummy data
GroupNo =[1 1 1 2 2 2 3 3 4]
A = randi(100,numel(GroupNo),2);
%list of all makers. if number of groups is greater than this you can use mod()
%to force a repeat back through list of markers.
%additionally you can make a list of colors too so you can have combinations of colors
%and markers to designate (though if you get that far plots are usually a mess at that point)
marker ='.ox+*sdv^<>ph';
hfig=figure(1);
hax =axes(hfig);
hold(hax,'on')
%loop through each unique group number and only plot those rows
for ind = 1:numel(unique(GroupNo))
%better way than h1,h2.... hN.
hplot(ind) = plot(hax,A(GroupNo==ind,1), A(GroupNo==ind,2),[marker(ind) '-'], 'markersize',10);
end

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by