Another Matlab Problem..Need help

Is the motion tracking stopping before it’s supposed to stop, or is it stopping when i=imax, which would be just after a couple of seconds (100 frames)?

There was no way (as far as I could tell) to exit the first version of your motion tracking code without an error occuring (while(noerror)), and if you halt your code with ctrl+c it exits and leaves the serial port open. I think the first thing I changed was the main while loop, from while(noerror) to while(i<imax) (I may not have made it clear though). The variable i is a frame counter, increased by 1 at the beginning of each loop, and imax is set to 100, so it should be halting after 100 frames. You can certainly increase imax, or change it back to run forever if you like.

I don’t have my webcam up on servos, but I am looking at the serial bytes Matlab is sending out and it seems to finish cleanly. Your servo controller has no idea if Matlab has the port open or not, it only sees the bytes that come its way.