How to Delete Rectangles with Loops
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Salvador Montes
il 18 Lug 2016
Commentato: Image Analyst
il 18 Lug 2016
Hello,
I am hoping that someone will help me with a problem I am having. I am trying to make a for loop in order to remove a number of given rectangles. However, I have notice that when I run the code and debug it, the deletion is not shown on the graph. I am not sure how to approach this. Even if this may be a simple problem, I would appreciate any input on this situation.
The Code:
axis([0 20 0 5])
rectangle('Position',[0,1,1,1])
rectangle('Position',[1,1,1,1])
rectangle('Position',[2,1,1,1])
rectangle('Position',[3,1,1,1])
rectangle('Position',[4,1,1,1])
rectangle('Position',[5,1,1,1])
rectangle('Position',[6,1,1,1])
rectangle('Position',[7,1,1,1])
rectangle('Position',[8,1,1,1])
rectangle('Position',[9,1,1,1])
rectangle('Position',[10,1,1,1])
rectangle('Position',[11,1,1,1])
rectangle('Position',[12,1,1,1])
rectangle('Position',[13,1,1,1])
rectangle('Position',[14,1,1,1])
rectangle('Position',[15,1,1,1])
x=15;
for i=1:10
h=rectangle('Position',[x,1,1,1])
H=findobj(h)
delete(h)
x=x-1;
M(i)=getframe
end
movie(M)
Thank you in advance.
0 Commenti
Risposta accettata
Stephen23
il 18 Lug 2016
Modificato: Stephen23
il 18 Lug 2016
You are drawing every rectangle twice: once hardcoded before the loop, and once inside the loop. This means deleting one of them has no effect because the other is still visible. Try this:
axis([0,20,0,5])
V = 1:15;
for k = V
hnd = rectangle('Position',[k,1,1,1]);
M(k)=getframe;
delete(hnd)
end
movie(M)
5 Commenti
Image Analyst
il 18 Lug 2016
No, it would be the 'units' property of the axes that you're drawing the rectangles on.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Graphics Performance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!