For porting to Matlab