Skip to Main Content Skip to Search
Product Documentation

Importing and Exporting Your Work

Exporting Your Work

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:

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.

Importing Your Work

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.

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 the Simulated Annealing solver, 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.

Generating a File

You may want to generate a file to continue with your optimization problem in the Command Window at another time. You can run the file without modification to recreate the results that you created with the Optimization Tool. You can also edit and modify the file and run it from the Command Window.

To export data from the Optimization Tool to a file, select File > Generate Code.

The generated file captures the following:

Running the file at the Command Window reproduces your problem results.

Although you cannot export your problem results to a generated file, you can save them in a MAT-file that you can use with your generated file, by exporting the results using the Export to Workspace dialog box, then saving the data to a MAT-file from the Command Window.

  


Free Optimization Interactive Kit

Learn how to use optimization to solve systems of equations, fit models to data, or optimize system performance.

Get free kit

Trials Available

Try the latest version of optimization products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS