restructured matlab for practical