Main Content

writeconstr

(Not recommended) Save optimization constraint description

Description

writeconstr is not recommended. Use write instead.

writeconstr(constr) saves a description of the optimization constraint constr in a file named constr.txt. Here, constr is the workspace variable name of the constraint. If writeconstr cannot construct the file name from the variable name, it writes the description to WriteConstrOutput.txt instead. writeconstr overwrites any existing file.

example

writeconstr(constr,filename) saves a description of the optimization constraint constr in a file named filename.

Examples

collapse all

Create an optimization constraint in terms of optimization variables, and save its description in a file.

x = optimvar('x',3,2);
cons = sum(x,2) <= [1;3;2];
writeconstr(cons,"TripleConstraint.txt")

The TripleConstraint.txt file contains the following text:

(1, 1)

  x(1, 1) + x(1, 2) <= 1

(2, 1)

  x(2, 1) + x(2, 2) <= 3

(3, 1)

  x(3, 1) + x(3, 2) <= 2

Input Arguments

collapse all

Optimization constraint, specified as an OptimizationEquality object, OptimizationInequality object, or OptimizationConstraint object. constr can represent a single constraint or an array of constraints.

Example: constr = x + y <= 1 is a single constraint when x and y are scalar variables.

Example: constr = sum(x) == 1 is an array of constraints when x is an array of two or more dimensions.

Path to the file, specified as a string or character vector. The path is relative to the current folder. The resulting file is a text file, so the file name typically has the extension .txt.

Example: "../Notes/steel_stuff.txt"

Data Types: char | string

Tips

  • To obtain the writeconstr information at the MATLAB® Command Window, use showconstr.

Version History

Introduced in R2017b

collapse all

R2019b: writeconstr is not recommended

The writeconstr function is not recommended. Instead, use write. The write function replaces writeconstr and many other problem-based functions.

There are no plans to remove writeconstr at this time.