Filter löschen
Filter löschen

About updating value of handles whithin loop

1 Ansicht (letzte 30 Tage)
Devendra Singh
Devendra Singh am 26 Okt. 2015
Kommentiert: Devendra Singh am 27 Okt. 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 Kommentar
Stephen23
Stephen23 am 26 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by