Added final function in matlab for the project