MATLAB: Matlab does not recognize the hasFrame for input type VideoReader

hasframevideo processingvideoreader

I'm trying to just run the code to get to learn how to mess with video files. Unfortunately, one of the functions (hasFrame) doesn't seem to be working . Every time I try to use it it seems to think that the file type VideoReader is not a legitimate input. the code :
vidObj = VideoReader('xylophone.mp4');
vidHeight = vidObj.Height;
vidWidth = vidObj.Width;
s = struct('cdata',zeros(vidHeight,vidWidth,3,'uint8'),...
'colormap',[]);
k = 1;
while hasFrame(vidObj)
s(k).cdata = readFrame(vidObj);
k = k+1;
end
error says :
Undefined function 'hasFrame' for input arguments of type 'VideoReader'.
is there some package I should have downloaded ? what's up with this?

Best Answer

isaironi - according to hasFrame, this function was introduced in version R2014b so you will need at least that version in order to make use of it. (If you are using an earlier version of MATLAB, you will probably have an issue with the http://www.mathworks.com/help/matlab/ref/videoreader.readframe.htm readframe> function too.)
As an alternative, try the following
numFrames = get(vidObj,'NumberOfFrames');
for k=1:numFrames
s(k).cdata = read(vidObj,k);
end