UPDATE:
Since I now understand that you need a circular buffer to store data, here's a solution you can use. Since you said you were storing centroid data of objects in an image, I will give you a general case for storing an arbitrary number of measurements (either 1 pixel index value for each centroid, or 2 values for x and y coordinates, etc.)...
First, initialize the buffer:
nBuffer = 10; % You can set this to whatever number of time points
% you want to store data for
nSamples = 2; % You can set this to the number of data values you
% need for each point in time
centroidBuffer = zeros(nSamples,nBuffer); % Initialize the buffer to zeroes
Next, you will have your continuous loop. You can use a while loop and a flag variable that initially has the value TRUE (and which you can set to FALSE to stop the loop):
keepLooping = true;
while keepLooping,
% Capture your image
% Compute the centroid data and place it in the vector "centroidData"
centroidBuffer = [centroidBuffer(:,2:end) centroidData(:)];
% Do whatever processing you want to do on centroidBuffer
% Choose to set keepLooping to false, if you want
end
This works in the following way: at each time point, the first column (i.e. the oldest data) in centroidBuffer is removed and a new column (i.e. the new data) is appended to the end. In this way, the buffer matrix is always the same size.
If you don't want to perform your processing at every time step, but instead only after every nBuffer time points so that it is operating on a new set of data each time, then replace the above code with the following:
keepLooping = true;
processTime = 0;
while keepLooping,
% Capture your image
% Compute the centroid data and place it in the vector "centroidData"
centroidBuffer = [centroidBuffer(:,2:end) centroidData(:)];
processTime = processTime+1;
if (processTime == nBuffer),
% Do whatever processing you want to do on centroidBuffer
processTime = 0;
end
% Choose to set keepLooping to false, if you want
end
EDIT:
There are a number of variations you can make with the above code. For example, if you want to store two sets of data with 10 time points each, you can change nBuffer to 20 to store the old set in the first 10 columns and the new set in the last 10 columns. Then, change the if statement to:
...
if (processTime == nBuffer/2),
...
And now you can perform your processing using both the older set of 10 data points (in centroidBuffer(:,1:10)) and the newer set of 10 data points (in centroidBuffer(:,11:20)).