fixed some bugs in matlab