Controlling a paddle in a GUI and making objects fall randomly, infinite loop. HELP

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

Respuestas (1)

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?

La pregunta está cerrada.

Preguntada:

el 9 de Mzo. de 2014

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by