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

조회 수: 10 (최근 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
Mario Malic
Mario Malic 2021년 11월 7일
Open the application in the debugging mode, and run the code step by step to figure out where the figure is being created.
It's impossible to figure out anything from this code.
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by