pushbutton to change the button string and function
Show older comments
I am using the GUI to make an image acquisition application.
I use a pushbutton to control the camera on and off. The initial string of the pushbutton was set to 'Connect' I can click it and make the camera work and the button string change to 'Disconnect'. But if I click it again, it will give me errors and the camera does not stop. The string doesn't change back to 'Connect'.
(errors:Matrix dimensions must agree.
Error in Image2DSnap>pushbutton1_Callback (line 87) if (handles.pushbutton1.String == 'Connect')
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in Image2DSnap (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Image2DSnap('pushbutton1_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback.)
Anybody can give me a hint?
Below is the relevant code:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (handles.pushbutton1.String == 'Connect')
vid = videoinput('gentl', 1);
vidRes = get(vid, 'VideoResolution');
hImage = image(zeros(vidRes(2), vidRes(1)), 'Parent', handles.Video);
preview(vid, hImage);
handles.pushbutton1.String = 'Disconnect';
% set(handles.pushbutton1,'string','Streaming','enable','off');
else
handles.pushbutton1.String = 'Connect';
closepreview
end
guidata(hObject, handles);
Accepted Answer
More Answers (0)
Categories
Find more on Image Preview and Device Configuration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!