Watch this Author's files
very useful; can be tailored to many situations.
it will help to me to develop a algo
Contact us at files@mathworks.com