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 Center および File ExchangeCreating, 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