Main Content

writeexpr

(Not recommended) Save optimization expression description

Description

writeexpr is not recommended. Use write instead.

writeexpr(expr) saves a description of the optimization expression expr in a file named expr.txt. Here, expr is the workspace variable name of the expression. If writeexpr cannot construct the file name from the expression, it writes the description to WriteExprOutput.txt instead. writeexpr overwrites any existing file.

example

writeexpr(expr,filename) saves a description of the optimization expression expr in a file named filename.

Examples

collapse all

Create an optimization variable and an expression that uses the variable. Save a description of the expression to a file.

x = optimvar('x',3,3);
A = magic(3);
var = sum(sum(A.*x));
writeexpr(var,"VarExpression.txt")

The VarExpression.txt file contains the following text:

  8*x(1, 1) + 3*x(2, 1) + 4*x(3, 1) + x(1, 2) + 5*x(2, 2) + 9*x(3, 2) + 6*x(1, 3) + 7*x(2, 3)
+ 2*x(3, 3)

Input Arguments

collapse all

Optimization expression, specified as an OptimizationExpression object.

Example: sum(sum(x))

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 writeexpr information at the MATLAB® Command Window, use showexpr.

Version History

Introduced in R2017b

collapse all

R2019b: writeexpr is not recommended

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

There are no plans to remove writeexpr at this time.