MATLAB: How to avoid recompiling all the MATLAB files that the main MATLAB file calls

ccompiledcompilerlibraryMATLAB Compilerstaticswitch

I am writing an MATLAB file application that relies on a lot of helper functions. Because the MATLAB compiler automatically compiles all the helper functions, the compile time can be considerably long. This can get even worse when I make changes to my MATLAB files and have to recompile all the MATLAB files. Is there a way to work around this problem? That is, is there a way to avoid recompiling all the helper MATLAB files each time I make changes to my MATLAB files?

Best Answer

The following solution works only for MATLAB compiler versions older than 4.0 (R14). For R14 and later there is no workaround for this problem.
There is no compiler option to only "re-compile what is required". However, what you can do is build a static library/object to hold all of the functions except the ones that you are changing most often and then recompile your application using the .mlib file.
For example, if you want to create a static library/object files from an MATLAB file that you will not need to recompile, called myfigure.m, you can do the following:
mcc -t -W lib:libmyfigure -T compile:lib myfigure.m
Now, if you type "ls", you can see that one of the files created is called libmyfigure.mlib. So if for example you have to recompile another MATLAB file, plot_test.m that calls myfigure.m, you can do this:
mcc -B sgl plot_test.m mfigure.o libmyfigure.mlib
This way, myfigure.m is a static object and will not be recompiled because of the .mlib file that's specified. If you are working with a lot of files it might be more convenient to implement this by using a make file.