# change the default font to mcode font for Matlab file in XeLatex

I am writing my thesis and got stuck up with this problem.

\usepackage{fontspec}
\setmainfont{Times New Roman}


and I compile the TEX file using XeLaTeX. In the appendix I need to put my MATLAB code. I have used \usepackage{mcode}.

When I run the file using XeLaTeX the fonts in my MATLAB code go to Times New Roman. But, I need the MATLAB code to be in default MATLAB font. How should I locally change the font?

First of all that shouldn't be the case. By default mcode uses the font Courier. See line 178-179 in mcode.sty:

% default font
\def\lstbasicfont{\fontfamily{pcr}\selectfont\footnotesize}


So what you want do to is redefine \lstbasicfont. As far as I remember MATLAB uses Helvetica as default font. So just add

\newfontfamily{\helvetica}{Helvetica}
\def\lstbasicfont{\helvetica\footnotesize}


after loading mcode.