About updating value of handles whithin loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Stephen23
le 26 Oct 2015
@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.
Réponses (1)
Dennie
le 26 Oct 2015
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.
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!