part of matlab code added