I am trying to display a changing rectangle in a loop with a pause, and it ignores the commit (which is actually assumed to be the default).
Here's a simplified version code:
clc; close all; clear all;
rect = [10 10 20 30];
figure
axis([0 200 0 50]);
for i = 1 : 15
rect(1) = rect(1) + i;
rectangle('Position', rect, 'edgeColor', [1 0 0]);
hold off;
pause(0.2);
end
Is it on purpose? Am I missing something? What can I do to make the previous rectangles disappear, except that they are printed in white after each iteration?
Thank..
edit:
A very simplified version has been resolved, but if I also want to draw one more thing in the same figure, the other section is ignored. What should I do in this case?
Thanks again.
clc; close all; clear all;
rect = [10 10 20 30];
figure
axis([0 200 0 50]);
h1 = [];
for i = 1 : 15
rect(1) = rect(1) + i;
delete(h1);
h1 = rectangle('Position', rect, 'edgeColor', [1 0 0]);
hold on
plot (5 + 5 * i, 5, '*g');
hold off
pause(0.2);
end
source
share