MATLAB: Unable to execute getdata in subfunction

frame capturegetdataguiImage Acquisition Toolboxwebcam

Hi, i have created a gui to capture image from webcam. however, there is error message whenever i press the push button. if codes in function cap is in main function, the work done properly. unfortunately my project requires me to capture image after pressing the push button.
can anyone help me pls?
my code
display=axes('Units','Pixels','Position',[120 120 640 480]);
vid = videoinput('winvideo',2,'YUY2_640x480');
vidRes = get(vid, 'VideoResolution');
nBands = get(vid, 'NumberOfBands');
hImage = image( zeros(vidRes(2), vidRes(1)) );
vid.FramesPerTrigger = 1;
function cap(hObject,event,vid)
global vid;
frame = getdata(vid);
clear all;
The error message is:
??? Undefined function or method 'getdata' for input arguments of type 'double'.
Error in ==> FYPGUI>cap at 44
frame = getdata(vid);
??? Error while evaluating uicontrol Callback

Best Answer

  • global variables must be declared as global in every function they are used in. You do not declare vid to be global in your main script.