# MATLAB: How to specify the directory where the S-function is generated using Real-Time Workshop’s S-Function target

I want the generated mexw32 file to go in a non-default location. I would like to know how I can specify the location.

• To set the output directory of your S-function target, modify the appropriate template makefile (TMF).
1. Find the appropriate TMF file in $MATLAB\rtw\c\rtwsfcn\ where$MATLAB is the MATLAB root directory on your machine, as returned by typing
matlabroot
at the MATLAB Command Prompt.
The filename will be rtwsfcn_(compiler).tmf. If you are using Visual Studio it will be rtwsfcn_vc.tmf, or if you are using the MATLAB default LCC, it will be rtwsfcn_lcc.tmf.
2. Copy or rename the TMF file to rtwfscn_(compiler)2.tmf.
3. Open rtwfscn_(compiler)2.tmf in the editor, and search for "-outdir".
4. There will be a line in the Rules section where it sets the MEX_FLAGS, and on one line will be:
-outdir ..
5. Replace the .. with the directory where you want the mexw32 file to be generated.
6. In the Real-Time Workshop options section of the Configuration Parameters dialog, set the TMF file to rtwfscn_(compiler)2.tmf instead of rtwsfcn_default_tmf.
7. When you build, the temporary directories will be generated in the working directory, but the S-function file will go to the location you specified for -outdir.