Problems with while. The program is blocked
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
I'm doing a graphical interface with app designer and I want a function to run while a condition is fulfilled but the problem is that the while is not executed and the application is blocked.
4 Kommentare
Guillermo Cid Espinosa
am 31 Okt. 2017
Bearbeitet: Guillaume
am 8 Nov. 2017
Adam
am 31 Okt. 2017
What do you mean by 'the application is blocked'? Have you use the debugger? Is app.PtButton.Value equal to 1? If so what happens when you step through with the debugger?
I assume you are expecting the loop to stop when the user changes the state of the button since nothing in your code ever changes it? It looks like it may be a case of the button state change not being registered until the loop has completed, which of course it never does if the button state is not being updated. I'm not too familiar with these aspects in App Designer though and don't have the time to setup a test program to look at it.
Guillermo Cid Espinosa
am 8 Nov. 2017
Bearbeitet: Guillermo Cid Espinosa
am 8 Nov. 2017
Antworten (1)
Guillaume
am 8 Nov. 2017
0 Stimmen
Disclaimer: I've never used the app designer. Maybe mathworks have changed how things work compared to the 'old' gui tools.
Matlab is single threaded. That means it can only do one thing at once. Therefore, when it is executing a loop, it's not going to respond to user events. Therefore, once your code has entered your loop it's going to look like the app is frozen as you never give a chance to matlab to check that your ptButton has changed state.
The fix for that is normally to insert a drawnow in your loop. drawnow tells matlab to actually update figures (without it, you won't see the changes made by your plot) and process the user events such as button clicks.
1 Kommentar
Guillermo Cid Espinosa
am 15 Nov. 2017
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!