replace.m

来自「求解线性矩阵不等式简单方便--与LMI工具箱相比」· M 代码 · 共 38 行

M
38
字号
function F = replace(F,X,W,expand)
%REPLACE        Substitutes variables in a SET object
%
%Z = REPLACE(F,X,W)  Replaces any occurence of the SDPVAR object Y 
%                    in the SDPVAR object X with the double W
%
% Example
%  x = sdpvar(1,1);
%  t = sdpvar(1,1);
%  F = set([1+t;1+x+t] > 0);
%  F = replace(F,x,2) generates F=set([1+t;3+t] > 0)

if nargin<4
    expand = 1;
end

if prod(size(W)) == 1
    W = repmat(W,size(X));
end

keep = [];

for i = 1:length(F.clauses)
    F.clauses{i}.data = replace(F.clauses{i}.data,X,W,expand);
    if isempty(F.clauses{i}.data) | isa(F.clauses{i}.data,'double')
        keep(i)=0;
    else
        keep(i)=1;
    end
end

F.clauses = {F.clauses{find(keep)}};

% Get new identifiers
F.LMIid = [];
for i = 1:length(F.clauses)
    F.LMIid = [F.LMIid yalmip('lmiid')];
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?