Watch this Author's files
Had to add xvec=[]; before line 50, and change isodd(i)==1 and isodd(i)==-1 to mod(i,2) and ~mod(i,2) on lines 64,67,68,71.
Great code otherwise.
Contact us at files@mathworks.com