How to set marker groups in one plot?

6 ビュー (過去 30 日間)
Leon
Leon 2020 年 2 月 17 日
コメント済み: Leon 2020 年 2 月 18 日
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!
  1 件のコメント
Leon
Leon 2020 年 2 月 18 日
Many thanks for your help!

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

採用された回答

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 Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by