Question
I made a Function that will get an AVI and remove the background by using Z-stack so the image is easier to track the moving objects. But i want to do this for a series of AVI files but i'm not sure where to start. I know i should use loop but i don't know how to input the location of the AVIs per loop. Basically i want the fuction to get say an AVI-1 and process it then process AVI-2, then AVI-3, etc. The Bold is the Function and the Italic is the description: Vid1 = VideoReader('Moviessmall.avi') %# Allow MATLAB to recognize the file by using VideoReader Vid1Frames = read(Vid1) %# RECOGNIZING the Frames in the movie Vid2Frames = rgb2gray(Vid1Frames); %# Change the movie to a GRAY SCALE movie. limiting the movie to 3 arrays Vid3Frames = Vid1Frames(:,:,1:450); %# Stacks Z-PROJECT VidB = median(Vid3Frames, 3); %# Run a MEDIAN to get a background image VidB2 = repmat(VidB, [1 1 450]); %# Because images need to be of the same FRAME number to Subtract a Frame duplication with repeat must be done Vid2 = Vid3Frames-VidB2; %# The SUBTRACTION to get an array Vid2 = Vid3Frames-VidB2; %# The SUBTRACTION to get an array
Expert Answer
John Williams
PhD Expert
Answered Aug 24, 2026
You could put the names of the files in a cell array then loop over the array.
% This array stores the names of the files.
C = {'Moviessmall.avi';'Moviessmall_2.avi';'Moviessmall3.avi'};
for ii = 1:length(C)
Vid1 = VideoReader(C{ii})
% The rest of your code... If you need to store data, use a cell.
end
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related matlab Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →