Matlab only runs a line is I pause before or in debug mode.
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a GUI with a listbox and a UITable.
The UITable has a cell selection callback. This callback changes the Value (selected items) of the listbox. This happens so that when I click an item in the UITable, that item is also selected in the Listbox.
I also have a button in my GUI with a Callback that runs a function which has the handles of the GUI as an input:
my_function(handles, someOtherData)
Inside my_function I update the data of the UITable, which makes the selection to become empty, and therefore the selection of the listbox to become empty. So, before this happens, I save my selected items into saved_selection.
However, after updating the UITable, I call
set(handles.my_listbox, 'Value', saved_selection)
but the selection in the Listbox is not set - it remains empty. The strange thing is that it works fine in debug mode (i.e. setting a break point somewhere and run line by line, everything works as it should, and the listbox selection is updated correctly). Also, if I add a pause(0.1) before the "set", it also works fine. But, if I use a pause(0.000001) it does not work. Thus, it seems like the set function is being run before it should.
I'm not sure what is causing this. Does Matlab run functions parallelly? If so, can it be that when I update the data in the UITable, that this process is running in parallel with the rest of my_function, and then the "set" is called before the update UITable is completed?
How can prevent this?
댓글 수: 0
채택된 답변
Sean de Wolski
2018년 4월 9일
편집: Sean de Wolski
2018년 4월 9일
Put a drawnow on the preceding line which will forcefully flush the event queue. Debug, pause, do this implicitly.
Also, consider using the much more modern app designer for your gui development. There is now a guide to app designer conversion tool if you have existing user interfaces to migrate.
doc appdesigner
댓글 수: 2
Sean de Wolski
2018년 4월 10일
편집: Sean de Wolski
2018년 4월 10일
You're welcome!
for ii = 1:100
plot(1:ii)
end
If you run this, you'll only see the final plot. MATLAB has offloaded 100 graphics events to an event queue but then keeps running and doesn't waste any time flushing those events. This is a feature most of the time. However, if you need access to those immediate events for the purpose of animation or user experience, you can force it with drawnow or pause(0.0001).
for ii = 1:100
plot(1:ii)
drawnow
end
Now you'll see all 100 iterations but it will take longer to run.
In apps, I tend to use drawnow fairly liberally when manipulating any graphics object.
App designer was first released in 16a and has been growing rapidly with every release since.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!