you can generate CasADi functions into C code, but not MATLAB functions containing CasADi code, as far as I know.
Also, if you are looking for a software framework which allows to generate efficient code for MPC after specifying your problem using CasADi symbolics, I can highly recommend you acados, see https://docs.acados.org/ for the documentation.
Good luck!