A new figure is coming out while plotting inside a for loop in App designer.

4 ビュー (過去 30 日間)
Trying to plot a 3D figure in the appdesiner but every time when is run the application it is opening a new figure window. I am not getting how to resolve this issue. Tried solutions given in some of the central questions but didn't worked. The part of the code is as
len_sum=sum(al);
xmin=-1.5*len_sum;
xmax=1.5*len_sum;
ymin=-1.5*len_sum;
ymax=1.5*len_sum;
zmin=-1.5*len_sum;
zmax=1.5*len_sum;
for i=1:length(app.T)
app.q=app.Y(i,1:n);
app.dq=app.Y(i,n+1:2*n)';
[so, sc, vc, tt, st] = for_kine(app,app.q, app.dq, n, alp, a, b, th, bt, r, dx, dy, dz);
B1X=[so(1,1), st(1,1)];
B1Y=[so(2,1), st(2,1)];
B1Z=[so(3,1), st(3,1)];
B2X=[so(1,2), st(1,2)];
B2Y=[so(2,2), st(2,2)];
B2Z=[so(3,2), st(3,2)];
app.tim=app.T(i);
app.tim=num2str(app.tim);
plot3(app.UIAxes_animation,B1X,B1Y,B1Z,B2X,B2Y,B2Z,'linewidth',2);
axis(app.UIAxes_animation,[xmin xmax ymin ymax zmin zmax]);
xlabel(app.UIAxes_animation,'X (m)','fontweight','normal','fontsize',10);
ylabel(app.UIAxes_animation,'Y (m)','fontweight','normal','fontsize',10);
zlabel(app.UIAxes_animation,'Z (m)','fontweight','normal','fontsize',10);
title(app.UIAxes_animation,['Current time t=',app.tim],'fontweight','normal','fontsize',10);
grid on;
drawnow;
end
  2 件のコメント
Saurabh Chaudhary
Saurabh Chaudhary 2021 年 11 月 7 日
thanks, I will try it out and get back to you.

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

採用された回答

Dave B
Dave B 2021 年 11 月 7 日
Short answer, replace:
grid on
with
grid(app.UIAxes_animation, 'on')
Long answer, if you look at this section of code:
plot3(app.UIAxes_animation,B1X,B1Y,B1Z,B2X,B2Y,B2Z,'linewidth',2);
axis(app.UIAxes_animation,[xmin xmax ymin ymax zmin zmax]);
xlabel(app.UIAxes_animation,'X (m)','fontweight','normal','fontsize',10);ylabel(app.UIAxes_animation,'Y (m)','fontweight','normal','fontsize',10);
zlabel(app.UIAxes_animation,'Z (m)','fontweight','normal','fontsize',10);
title(app.UIAxes_animation,['Current time t=',app.tim],'fontweight','normal','fontsize',10);
grid on;
You'll see that for the first 5 lines you're specifying a target. For example, for plot3 - you say that the place you want to plot is in app.UIAxes_animation. But for the last line, grid on, you haven't specified a target. When you don't specify a target with a MATLAB graphics command, MATLAB will use the current axes, and if there isn't a current axes then one will be created (and a figure will be created if there isn't a current figure). Because the uiaxes in an app isn't selected as a current axes, grid has created one for you.
  1 件のコメント
Saurabh Chaudhary
Saurabh Chaudhary 2021 年 11 月 8 日
Thankyou, it is working fine.

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

その他の回答 (0 件)

カテゴリ

Find more on Interactive Control and Callbacks in Help Center and File Exchange

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by