About updating value of handles whithin loop
1 次查看(过去 30 天)
显示 更早的评论
function pushbutton4_Callback(hObject, eventdata, handles)
handles.st=1
guidata(hObject, handles);
this is the code to stop video with push button, to start the video:
function pushbutton2_Callback(hObject, eventdata, handles)
info=imaqhwinfo('winvideo')
vid=videoinput('winvideo',1)
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 50;
start(vid)
sto=0;
while(sto==0)
if(vid.FramesAcquired>=10)
break;
end
data = getsnapshot(vid);
axes(handles.axes1)
imshow(data)
guidata(hObject, handles);
drawnow;
pause(2);
sto=handles.st
end
the problem is when i press stop button and update st to 1 it take sto as well as st 0 always
1 个评论
Stephen23
2015-10-26
@Devendra Singh: I formatted your code correctly for you, but in future you can do it yourself by selecting the code text and then clicking the {} Code button. It also helps if you do not have empty lines as every alternate line of the code.
回答(1 个)
Dennie
2015-10-26
Matlab GUI's use callbacks to handle the button interrupts. However, the callbacks cannot interrupt each other. Matlab use a sequential method for this, meaning that when you press two buttons in the GUI it first finishes the first callback and afterwards the second. This is the reason that your value is not being updated during the while loop.
A trick that you could try to break the loop is using a toggle stop button and read out that value in the loop
while(sto==0)
if(vid.FramesAcquired>=10)
break;
end
data = getsnapshot(vid);
axes(handles.axes1)
imshow(data)
guidata(hObject, handles);
drawnow;
pause(2);
sto=get(handles.stopbutton,'Value');
end
This will force matlab to read out the current value of the button and since you use a toggle button, you don't have to worry about timing.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!