The Optimization Toolbox allows optimization options that graph the result of running the routine. These options use graphics plot commands to show the results. That is why compiling lsqnonlin.m will result in references to these many functions.
There are two recommended ways to work around this limitation:
1. Use the C/C++ graphics library (preferred)
2. Stub out the calls to the MATLAB files involved with the graphics library and disable the associated warning messages.
In order to accomplish the second option, you will need to create a directory containing MATLAB files that are stub versions of the functions in .../toolbox/matlab/graphics, .../toolbox/matlab/graph2d, etc. The MATLAB compiler must be told to examine this directory containing the stub files prior to finding the directory with the actual handle graphics functions in it.
It works like this:
1. Create a directory to contain the stub MATLAB files (hgstubs for example)
2. Populate it with versions of the MATLAB Files from the graphics toolbox with the following definition:
function [varargout] = close( varargin )
error('Graphics functions are not compiled into this application');
These functions will cause an error if they are called in the compiler-generated code.
3. Use the following compilation command from within MATLAB:
mcc -I hgstubs -mvg lsqnonlin -w ...
disable:using_graphics_function
This will cause lsqnonlin to be compiled to produce an error if any of the handle graphics functions are called.
4. In order to use this trick when compiling from the DOS or Unix Shell prompt, you must ensure that the hgstubs directory is on the compiler path prior to the directories containing the graphics functions in MATLAB.
- You must NOT use a saved path in your preferences directory
- You must manually specify the saved path file on the command line after the hgstubs directory.
mcc -I hgstubs -B <mysavedpathfile> -mvg lsqnonlin -w disable:using_graphics_function
5. The specific graphics library functions that will need to be stubbed out for lsqnonlin are:
close, subplot, xlabel, ylabel, legend, and title
Best Answer