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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!