some changes to matlab and c++ code