bug in matlab code fixed