Fix bug that breaks MATLAB 2014a compilation

Change how mex is called to fix broken compilation with MATLAB 2014a. I've tested this with 2014a and 2012b (2012b was working previous to this change and continues to work with this fix). This PR may address issues that people have been reporting (e.g., #605, #677).