About updating value of handles whithin loop

2 visualizzazioni (ultimi 30 giorni)
Devendra Singh
Devendra Singh il 26 Ott 2015
Commentato: Devendra Singh il 27 Ott 2015
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 Commento
Stephen23
Stephen23 il 26 Ott 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.

Accedi per commentare.

Risposte (1)

Dennie
Dennie il 26 Ott 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.
  1 Commento
Devendra Singh
Devendra Singh il 27 Ott 2015
Dennie Sir,could you please suggest what to write in toggle button callbacks .

Accedi per commentare.

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by