How to Plot on UI Axes with app designer?
236 ビュー (過去 30 日間)
古いコメントを表示
I am trying to have a graph ploted on the UI Axes in my GUI that does not open a new figure but instead just changes the graph that is being shown.
I would like to graph just individual points on said graph and be able to change the axis of the graph through edit windows and use a "plot" button to have the points added.
My current code looks like this:
function PlotButtonPushed(app, event)
vecx = str2double(strsplit(app.XValuesEditField.Value));
vecy = str2double(strsplit(app.YValuesEditField.Value));
Lx_val = length(vecx);
Ly_val = length(vecy);
min_X = app.XminEditField.Value;
max_X = app.XmaxEditField.Value;
scale = (max_X-min_X)/5;
max_Y = app.YmaxEditField.Value;
min_Y = app.YminEditField.Value;
scale1 = (max_Y-min_Y)/5;
selectedButton(1) = app.Color.SelectedObject;
if selectedButton(1) == app.Red
C = 2;
elseif selectedButton(1) == app.Green
C = 3;
else
C = 1;
end
selectedButton(2) = app.Shape.SelectedObject;
if selectedButton(2) == app.Dashed
S = 2;
elseif selectedButton(2) == app.Solid
S = 3;
else
S =1;
end
if C==1 && S==1
if Lx_val == Ly_val
i = 1;
while i <= Lx_val
hold on;
plot(app.UIAxes,vecx(i),vecy(i),'ko');
app.UIAxes.YTickLabel = [min_Y:scale1:max_Y];
app.UIAxes.XTickLabel = [min_X:scale:max_X];
xlim(app.UIAxes,[min_X max_X]);
ylim(app.UIAxes,[min_Y max_Y]);
i = i+1;
end
end
end
When I run the file I can edit the axis of the graph initially without issue, however once I hit plot and it runs this piece of code here, it opens an empty plot figure, plots the final point that I ask it to, and squishes my x and y axis into the bottom left corner like the image I have attached. (If the way the code is in the body is sloppy I can always take a screenshot of that as well!). If anybody could help I would really appreciate it.
0 件のコメント
回答 (1 件)
Geoff Hayes
2020 年 11 月 10 日
hold on;
with
hold(app.UIAxes, 'on');
where you specify which axes you want to apply the hold to.
2 件のコメント
Geoff Hayes
2020 年 11 月 11 日
Cameron - I suspect what is happening is that your data contains values outside of the limits set by the axes, and (for whatever reason) those limits aren't being respected. Try setting the limits after the plots have been drawn to the axes
hold(app.UIAxes, 'on'); % this may work outside of the loop too but please check
while i <= Lx_val
plot(app.UIAxes,vecx(i),vecy(i),'ko');
i = i+1;
end
% now set the limits
app.UIAxes.YTickLabel = [min_Y:scale1:max_Y];
app.UIAxes.XTickLabel = [min_X:scale:max_X];
xlim(app.UIAxes,[min_X max_X]);
ylim(app.UIAxes,[min_Y max_Y]);
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!