You don't need to do this:
sprintf('%s','That was all about Image tracking, Guess that was pretty easy :) ')
instead just do this:
sprintf('That was all about Image tracking, Guess that was pretty easy :) \n');
To save the coordinates, you need to index it.
Get rid of this from the loop:
allCentroids = [measurements.Centroid];
centroidX = allCentroids(1:2:end);
centroidY = allCentroids(2:2:end);
Then save allCentroids in a cell array (since it may have a variable number of centroids per frame) right after you call regionprops() on that frame:
stats = regionprops(bw, 'BoundingBox', 'Centroid');
allCentroids{frameNumber} = vertcat(stats.Centroid);
frameNumber = frameNumber + 1;
Make sure you initialize frameNumber before the while loop
After that, you can do whatever you want, like call save() to store it in a .mat file on disk, or whatever you want.
Best Answer