Hold Off Not Working in For Loop Dynamic 3D Plotting

조회 수: 15 (최근 30일)
Shantanu Jha
Shantanu Jha 2015년 8월 13일
댓글: Mike Garrity 2015년 8월 14일
Hello I have been struggling with this for some time today. Although at some point in time this was working fine, I am now unable to make my dynamic plot without the previous instances of the plot being stored. I am using "hold off"; however, I am unable to fix this.
Here is the part of my code that graphs my hand motion model:
finger_r = 1.5;
thumb_r = 1.6;
n = 20;
cyl_color = 'yellow';
closed = 1;
lines = 0;
for j = 1:Size
%Coordinate Set
%Pinky 1
xyz_begin_1_1 = [1.5 0 0];
xyz_end_1_1 = [x_1_1(j) y_1_1(j) z_1_1(j)] + xyz_begin_1_1;
%Pinky 2
xyz_begin_2_1 = xyz_end_1_1;
xyz_end_2_1 = [x_2_1(j) y_2_1(j) z_2_1(j)] + xyz_begin_2_1;
%Ring 1
xyz_begin_1_2 = [5 0 0];
xyz_end_1_2 = [x_1_2(j) y_1_2(j) z_1_2(j)] + xyz_begin_1_2;
%Ring 2
xyz_begin_2_2 = xyz_end_1_2;
xyz_end_2_2 = [x_2_2(j) y_2_2(j) z_2_2(j)] + xyz_begin_2_2;
%Middle 1
xyz_begin_1_3 = [8.5 0 0];
xyz_end_1_3 = [x_1_3(j) y_1_3(j) z_1_3(j)] + xyz_begin_1_3;
%Middle 2
xyz_begin_2_3 = xyz_end_1_3;
xyz_end_2_3 = [x_2_3(j) y_2_3(j) z_2_3(j)] + xyz_begin_2_3;
%Index 1
xyz_begin_1_4 = [13 0 0];
xyz_end_1_4 = [x_1_4(j) y_1_4(j) z_1_4(j)] + xyz_begin_1_4;
%Index 2
xyz_begin_2_4 = xyz_end_1_4;
xyz_end_2_4 = [x_2_4(j) y_2_4(j) z_2_4(j)] + xyz_begin_2_4;
%Thumb 1
xyz_begin_1_5 = [15 -10 0];
xyz_end_1_5 = [x_1_5(j) y_1_5(j) z_1_5(j)] + xyz_begin_1_5;
%Thumb 2
xyz_begin_2_5 = xyz_end_1_5;
xyz_end_2_5 = [x_2_5(j) y_2_5(j) z_2_5(j)] + xyz_begin_2_5;
%Plot Rectangle Hand
Cylinder([7.5 0 -7.5],[7.5 -10 -7.5],7.5,n,cyl_color,closed,lines)
%Plotting Fingers -----------------------------------------------------
%Pinky
Cylinder(xyz_begin_1_1,xyz_end_1_1,finger_r,n,cyl_color,closed,lines)
Cylinder(xyz_begin_2_1,xyz_end_2_1,finger_r,n,cyl_color,closed,lines)
%Ring
Cylinder(xyz_begin_1_2,xyz_end_1_2,finger_r,n,cyl_color,closed,lines)
Cylinder(xyz_begin_2_2,xyz_end_2_2,finger_r,n,cyl_color,closed,lines)
%Middle
Cylinder(xyz_begin_1_3,xyz_end_1_3,finger_r,n,cyl_color,closed,lines)
Cylinder(xyz_begin_2_3,xyz_end_2_3,finger_r,n,cyl_color,closed,lines)
%Index
Cylinder(xyz_begin_1_4,xyz_end_1_4,finger_r,n,cyl_color,closed,lines)
Cylinder(xyz_begin_2_4,xyz_end_2_4,finger_r,n,cyl_color,closed,lines)
%Thumb
Cylinder(xyz_begin_1_5,xyz_end_1_5,thumb_r,n,cyl_color,closed,lines)
Cylinder(xyz_begin_2_5,xyz_end_2_5,thumb_r,n,cyl_color,closed,lines)
axis([-20 20 -20 20 -20 20])
drawnow
hold off
end
All of the instances of my dynamic plot are staying on the figure. I want the graph to clear the previous instance every time it graphs a new iteration of my for loop.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 14일
"hold off" only works if the current axes happens to be the same as the axes the plots are drawn in. As we do not know anything about the Cylinder routine we cannot say what it is doing.
  댓글 수: 1
Mike Garrity
Mike Garrity 2015년 8월 14일
In addition, hold is about functions that make "charts". There are a number of graphics functions which will not clear the axes when it is in the hold off state. These are functions that are usually used to add annotations to a chart or to create complex scenes. Examples include:
  • text
  • line
  • patch
  • ...
If you're using these instead of the charting functions, then you need to manage the contents of the axes yourself. You can either:
  • Keep the handles these functions return, and call delete on them
  • Use cla to clear everything in the axes

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by