fixed matlab code