Fixed some issues with matlab interface.
Added some assertions.