| Optimization Toolbox™ | ![]() |
| On this page… |
|---|
The Export to Workspace dialog box enables you to send your problem information to the MATLAB® workspace as a structure that you may then manipulate in the Command Window.
To access the Export to Workspace dialog box shown below, select File > Export to Workspace.

You can specify a structure that contains:
The problem and options information
The problem and options information, and the state of the solver when stopped (this means the latest point for most solvers, the current population for Genetic Algorithms solvers, and the best point found for Simulated Annealing and Threshold Acceptance solvers)
The states of random number generators rand and randn at the start of the previous run, by checking the Use random states from previous run box for applicable solvers
The options information only
The results of running your problem in optimtool
Exported results structures contain all optional information. For example, an exported results structure for lsqcurvefit contains the data x, resnorm, residual, exitflag, output, lambda, and jacobian.
After you have exported information from the Optimization Tool to the MATLAB workspace, you can see your data in the MATLAB Workspace browser or by typing the name of the structure at the Command Window. To see the value of a field in a structure, double-click on the structure in the Workspace window. Alternatively, see the values by entering structurename.fieldname at the command line. For example, so see the message in an output structure, enter output.message. If a structure contains structures, you can double-click again in the workspace browser, or enter structure1.structure2.fieldname at the command line. For example, to see the level of iterative display contained in the options structure of an exported problem structure, enter optimproblem.options.Display.
You can run a solver on an exported problem at the command line by typing
solver(problem)
For example, if you have exported a fmincon problem named optimproblem, you can type
fmincon(optimproblem)
This runs fmincon on the problem with the saved options structure contained in optimproblem. You can exercise more control over outputs by typing, for example,
[x,fval,exitflag] = fmincon(optimproblem)
or use any other supported syntax.
Whether you saved options from Optimization Toolbox™ functions at the Command Window or if you exported options, or the problem and options, from the optimtool, you can resume work on your problem using the optimtool.
There are three ways to import your options, or problem and options, to optimtool.
Call the optimtool function from the Command Window specifying your options, or problem and options, as the input, tor example,
optimtool(options)
Select File > Import Options in the Optimization Tool.
Select File > Import Problem in the Optimization Tool.
The methods described above require that the options, or problem and options, be present in the MATLAB workspace.
If you import a problem that was generated with the Include information needed to resume this run box checked, the initial point is the latest point generated in the previous run. (For Genetic Algorithm solvers, the initial population is the latest population generated in the previous run. For Simulated Annealing and Threshold Acceptance solvers, the initial point is the best point generated in the previous run.) If you import a problem that was generated with this box unchecked, the initial point (or population) is the initial point (or population) of the previous run.
You may want to generate an M-file to continue with your optimization problem in the Command Window at another time. You can run the M-file without modification to recreate the results that you created with the Optimization Tool. You can also edit and modify the M-file and run it from the Command Window.
To export data from the Optimization Tool to an M-file, select File > Generate M-file.
The M-file captures the following:
The problem definition, including the solver, information on the function to be minimized, algorithm specification, constraints, and start point
The options (using optimset) with the currently selected option value
Running the M-file at the Command Window reproduces your problem results.
Although you cannot export your problem results to a generated M-file, you can save them in a MAT-file that you can use with your generated M-file, by exporting the results using the Export to Workspace dialog box, then saving the data to a MAT-file from the Command Window.
![]() | Getting Help in the Optimization Tool | Optimization Tool Examples | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |