Plot different markers on the same graph based on “if-else” statement (third parameter) in AppDesigner

조회 수: 1 (최근 30일)
Hi,
I have a table of data that I read from Excel using readtable in AppDesigner. The data consists of Lat,Long and Type.
Based on "Type", I would like to plot the Lat (Y) and Long (X) using 2 different markers.
i.e. if Type="A", plot the X & Y coordinates using "+" type marker.
if Type = "B", plot the X & Y coordinates using "square" type marker.
I have try using this kind of coding
.....
.....
.....
t = readtable(Grid.xlsx,opts);
app.UITable.Data = t;
x = app.UITable.Data.Long;
y = app.UITable.Data.Lat;
hold(app.UIAxes,'on')
if strcmp (app.UITable.Data.Type, 'A')
scatter(app.UIAxes,x,y,'+','black');
else
scatter(app.UIAxes,x,y,'square','blue');
end
However, MATLAB plots all the X & Y coordinates using the "+" type marker.
Please advise and thanks in advance

채택된 답변

Cameron
Cameron 2023년 4월 5일
편집: Cameron 2023년 4월 5일
You should use indexing instead.
t = readtable(Grid.xlsx,opts);
app.UITable.Data = t;
x = app.UITable.Data.Long;
y = app.UITable.Data.Lat;
groupA = string(app.UITable.Data.Type) == "A";
groupB = string(app.UITable.Data.Type) == "B";
hold(app.UIAxes,'on')
scatter(app.UIAxes,x(groupA),y(groupA),'+','black');
scatter(app.UIAxes,x(groupB),y(groupB),'s','blue');
hold(app.UIAxes,'off')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by