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

2 次查看(过去 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