Added some code for Matlab mode, not complete.