Get rid of the "clear" in that function, after the tic statement.
That clear is deleting whatever you passed in for img and origin via the input argument list.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!