This is a total application specific routine and not generic at all. Matlab has buuilt-in functions to perform more generic tasks. The lack of documentation adds more fuel to the fire. Finally, where does it fit? Generally a series of images in the form of successive frames are converted to an avi file from Matlab. I don't see any application or integrity in this case!