Controlling a paddle in a GUI and making objects fall randomly, infinite loop. HELP
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Attached is my file for my app im making in a GUI controlled by an accelerometer. I have the paddle moving on its own controlled by the accelerometer. Below is a code that makes circles fall down from the top at random positions and velocities. However when I combine the 2 codes Im stuck in an infinite loop and dont know why. Help please.
for num_of_objects=10; positionx=randi([-100 100],1000,1); velocity=(randi([20 60],1000,1))/100; new_velocity=zeros(1000,1); count=.5;
while true
cla
limits=[-100 100 -100 100];
axis(limits);
hold on
for i=1:num_of_objects;
circle(positionx(i),150-new_velocity(i),3);
new_velocity(i)=new_velocity(i) + velocity(i);
count=count+0.001;
num_of_objects= round(count);
if 150-new_velocity(i) < -10;
new_velocity(i)=0;
positionx(i)=randi([-100 100],1,1);
velocity(i)=(randi([20 60],1,1))/100;
end
end
end
guidata(hObject, handles);
end
Answers (1)
Image Analyst
on 9 Mar 2014
0 votes
Yes, it will be an infinite loop because you just have "while true" and no "break" inside the loop so there's no way to get out of it. How or why did you ever expect to break out of the while loop?
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!