MATLAB: How to use VideoReader to read a variable file name

Image Acquisition ToolboxMATLABmotion detectionvideovideo importvideoreader

I am writing a function that will call many videos and take certain frames from them. I am trying to use a loop in order to allow for the function to read the video names in a folder and place them in VideoReader so I can look through many videos without having to import each video individually.
The general area of issue in the code is here:
videos = dir(videoFolder);
for k=3:length(videos)
vidName = videos(k).name;
v = VideoReader(vidName);
%motion detection code follows
end
where vidName returns the desired name but I believe VideoReader is searching for the file named "vidName" as opposed to the video file name it represents. I receive this error:
Error using VideoReader/init (line 601)
The filename specified was not found in the MATLAB path.
Error in VideoReader (line 171)
obj.init(fileName);
Error in motion_detection (line 12)
v = VideoReader('vidName');

Best Answer

The bug is clear in the error message: you supply a char vector like this:
v = VideoReader('vidName');
when you should be supplying the variable itself, like this:
v = VideoReader(vidName);
Related Question