C and Matlab code