Transfered python code to matlab code (untested)