MATLAB: Undefined function or method ‘getCameraInfo’

camerainfo

I am trying to capture a frame from webcam,for hat i used the coding below
a = imaqhwinfo;
[camera_name, camera_id, format] = getCameraInfo(a);
vid = videoinput(camera_name, camera_id, format);
% Set the properties of the video object
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
function [camera_name, camera_id, resolution] = getCameraInfo(a)
camera_name = char(a.InstalledAdaptors(end));
camera_info = imaqhwinfo(camera_name);
camera_id = camera_info.DeviceInfo.DeviceID(end);
resolution = char(camera_info.DeviceInfo.SupportedFormats(end));
i get the below error
??? Undefined function or method 'getCameraInfo' for input arguments of type
'struct'
please tell how to rectify it

Best Answer

Where have you saved your function getCameraInfo?
Once you create the getCameraInfo.m file, you have to save it in a folder and then add that folder to the MATLAB path, so that MATLAB knows how to find the function.
Use addpath or pathtool to add the folder to the MATLAB path.
For example, assume that you have saved getCameraInfo.m in a folder called
mfiles, use
>>addpath 'c:\mfiles'
Obviously the above command is slightly different on linux or Mac.
Or simply enter
>>pathtool
and add the folder using the GUI.