How to set marker groups in one plot?

3 次查看(过去 30 天)
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!

采纳的回答

Joseph Cheng
Joseph Cheng 2020-2-18
编辑:Joseph Cheng 2020-2-18
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by