Converting .m file to .mex is exactly what MATLAB Coder is about.
Open MATLAB Coder App and follow the steps. Leave the "fixed point conversion" set to "none". At the end of the steps, pick "mex" as your target and continue. Once the build is over, you'll get a mex file.