필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Problems with while. The program is blocked

조회 수: 2 (최근 30일)
Guillermo Cid Espinosa
Guillermo Cid Espinosa 2017년 10월 30일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Adam
Adam 2017년 10월 31일
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
Guillermo Cid Espinosa 2017년 11월 8일
편집: Guillermo Cid Espinosa 2017년 11월 8일
If I run the program the application is blocked. I can not activate any of the functions programmed in the app or close it. I need to press ctrl + Alt + Sup to close matlab. On the other hand I have seen in the workspace that several data packages are received although these are not represented in the graph so app.Button.Value is equal to one. So it seems that the while is running now but I can not get the data to appear in the graph.
The main problem is that it always receives the same data (several times while the button is connected) only if I go back to disconnect and connect the PtButton receives new data

답변 (1개)

Guillaume
Guillaume 2017년 11월 8일
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
Guillermo Cid Espinosa
Guillermo Cid Espinosa 2017년 11월 15일
Thanks for answering. But the problem is that the data received from the micro is not updated despite the function fprintf. The most data are always received and displayed.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by