MATLAB app designer button
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
lital levy
el 29 de Ag. de 2022
Comentada: Marek
el 8 de En. de 2025
hi, in the app designer i created a 'start' button that starts the action of a long loops, and i want to create a 'stop' button that will immidietly stop the action of the first button and not waite until it finished the loops, is that possible?
0 comentarios
Respuesta aceptada
Ankit
el 29 de Ag. de 2022
Editada: Ankit
el 30 de Ag. de 2022
Please find attached *.zip file where you can see one example (refer below code)
properties (Access = public)
stop_sim = false;
end
methods (Access = private)
function stopSimulation(app)
app.stop_sim = true;
msgbox('simulation stopped');
end
function startSimulation(app)
i = 0;
while i<=1000000 && app.stop_sim == false
app.display.Value = num2str(i);
pause(0);
i = i + 1;
end
end
end
function StartButtonPushed(app, event)
startSimulation(app)
end
function StopButtonPushed(app, event)
stopSimulation(app)
end
Once the user pushes the StopButtonPushed button, for which the function "stopSimulation" is a callback, then the app fetch the updated properties and the condition to app.stop_sim will be set to true and hence this allows the app to terminate the while loop before reaching 1000000 iterations.
3 comentarios
Ankit
el 29 de Ag. de 2022
above function will break the loop as soon as you click the stop button right?
Marek
el 8 de En. de 2025
Hi, I built my program according to your example and observed behavior which I don't understand. Can you help me to understand this question?
When I put the Matlab optimization function (fmincon) inside the loop the stop button stops working. Namely, the stopSimulation function was performed AFTER the lop was finished.
By trial and error, I figured that changing pause(0) to pause(0.01) solved this problem. By trial and error, I figured that changing pause(0) to pause(0.01) solved this problem. The value of 0.005 seconds was too short. When I put 0.008 s the function made one or two additional iterations and stopped correctly. The one iteration takes 1 to 2 seconds, and I have a clear indicator of the actual stage, therefore I'm pretty sure that observation is correct.
The program works, but I would like to understand better why the value of pause time makes such a big difference.
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!