MATLAB 帮助中心
(不推荐)保存优化约束说明
writeconstr(constr)
writeconstr(constr,filename)
不推荐使用 writeconstr。请改用 write。
writeconstr
write
writeconstr(constr) 将优化约束 constr 的说明保存在名为 constr.txt 的文件中。此处,constr 是约束的工作区变量名称。如果 writeconstr 无法根据变量名称构造文件名,它会将说明写入 WriteConstrOutput.txt。writeconstr 会覆盖任何现有文件。
constr
.txt
WriteConstrOutput.txt
writeconstr(constr,filename) 将优化约束 constr 的说明保存在名为 filename 的文件中。
filename
示例
全部折叠
根据优化变量创建优化约束,并将其说明保存在文件中。
x = optimvar('x',3,2); cons = sum(x,2) <= [1;3;2]; writeconstr(cons,"TripleConstraint.txt")
TripleConstraint.txt 文件包含以下文本:
TripleConstraint.txt
(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
OptimizationEquality
OptimizationInequality
OptimizationConstraint
优化约束,指定为 OptimizationEquality 对象、OptimizationInequality 对象或 OptimizationConstraint 对象。constr 可以表示单个约束或约束数组。
示例: 当 x 和 y 是标量变量时,constr = x + y <= 1 是单个约束。
x
y
constr = x + y <= 1
示例: 当 x 是二维或多维数组时,constr = sum(x) == 1 是约束数组。
constr = sum(x) == 1
文件的路径,指定为字符串或字符向量。路径是相对于当前文件夹的路径。生成的文件是文本文件,因此文件名通常具有扩展名 .txt。
示例: "../Notes/steel_stuff.txt"
"../Notes/steel_stuff.txt"
数据类型: char | string
char
string
要在 MATLAB® 命令行窗口中获取 writeconstr 信息,请使用 showconstr。
showconstr
不推荐使用 writeconstr 函数。请改用 write。write 函数取代了 writeconstr 和许多其他基于问题的函数。
目前没有删除 writeconstr 的计划。
OptimizationConstraint | show | write
show
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处