|On this page…|
You can specify any available patternsearch options by passing an options structure as an input argument to patternsearch using the syntax
[x fval] = patternsearch(@fitnessfun,nvars, ... A,b,Aeq,beq,lb,ub,nonlcon,options)
Pass in empty brackets  for any constraints that do not appear in the problem.
You create the options structure using the function psoptimset.
options = psoptimset(@patternsearch)
This returns the options structure with the default values for its fields.
options = TolMesh: 1.0000e-006 TolCon: 1.0000e-006 TolX: 1.0000e-006 TolFun: 1.0000e-006 TolBind: 1.0000e-003 MaxIter: '100*numberofvariables' MaxFunEvals: '2000*numberofvariables' TimeLimit: Inf MeshContraction: 0.5000 MeshExpansion: 2 MeshAccelerator: 'off' MeshRotate: 'on' InitialMeshSize: 1 ScaleMesh: 'on' MaxMeshSize: Inf InitialPenalty: 10 PenaltyFactor: 100 PollMethod: 'gpspositivebasis2n' CompletePoll: 'off' PollingOrder: 'consecutive' SearchMethod:  CompleteSearch: 'off' Display: 'final' OutputFcns:  PlotFcns:  PlotInterval: 1 Cache: 'off' CacheSize: 10000 CacheTol: 2.2204e-016 Vectorized: 'off' UseParallel: 'never'
The patternsearch function uses these default values if you do not pass in options as an input argument.
The value of each option is stored in a field of the options structure, such as options.MeshExpansion. You can display any of these values by entering options followed by the name of the field. For example, to display the mesh expansion factor for the pattern search, enter
options.MeshExpansion ans = 2
To create an options structure with a field value that is different from the default, use psoptimset. For example, to change the mesh expansion factor to 3 instead of its default value 2, enter
options = psoptimset('MeshExpansion',3);
This creates the options structure with all values set to empty except for MeshExpansion, which is set to 3. (An empty field causes patternsearch to use the default value.)
If you now call patternsearch with the argument options, the pattern search uses a mesh expansion factor of 3.
If you subsequently decide to change another field in the options structure, such as setting PlotFcns to @psplotmeshsize, which plots the mesh size at each iteration, call psoptimset with the syntax
options = psoptimset(options, 'PlotFcns', @psplotmeshsize)
This preserves the current values of all fields of options except for PlotFcns, which is changed to @plotmeshsize. Note that if you omit the options input argument, psoptimset resets MeshExpansion to its default value, which is 2.
You can also set both MeshExpansion and PlotFcns with the single command
options = psoptimset('MeshExpansion',3,'PlotFcns',@plotmeshsize)
As an alternative to creating the options structure using psoptimset, you can set the values of options in the Optimization app and then export the options to a structure in the MATLAB® workspace, as described in the Importing and Exporting Your Work section of the Optimization Toolbox™ documentation. If you export the default options in the Optimization app, the resulting options structure has the same settings as the default structure returned by the command
options = psoptimset
except for the default value of 'Display', which is 'final' when created by psoptimset, but 'none' when created in the Optimization app.
You can also export an entire problem from the Optimization app and run it from the command line. Enter
where problem is the name of the exported problem.