📄 subsasgn.m
字号:
function Pi = subsasgn(P,S,B)
% SUBSASGN -- assignment to subscripted matrix polynomial
%
% This function is not meant to be called by the user. It is called by
% Matlab when a subscripted matrix polynomial appears on the
% left-hand side of an operation.
%
% The only allowed operations are
%
% P.min = Pmin change starting exponent
% P.coef = C change coefficients
% P.type = 'type' change type
% P.m = m change dilation factor
% P.r = r change multiplicity
%
% P{i} = matrix Change an individual coefficient matrix
% An assignment with index outside
% existing limits is allowed, and
% increases the size of P.
%
% P(submatrix) = M insert matrix polynomial as submatrix
% An assignment with index outside
% existing limits is allowed, and
% increases the size of P.
% Copyright (c) 2004 by Fritz Keinert (keinert@iastate.edu),
% Dept. of Mathematics, Iowa State University, Ames, IA 50011.
% This software may be freely used and distributed for non-commercial
% purposes, provided this copyright statement is preserved, and
% appropriate credit for its use is given.
%
% Last update: Feb 20, 2004
switch S.type
case '.' % reset min, coef, type, m, r
Pi = set(P,S.subs,B);
case '()' % insert matrix polynomial as submatrix
if (isnumeric(P) & ~isnumeric(B))
P = sym(P);
end
% determine starting/ending subscripts of result
if ~isa(B,'mpoly')
B = mpoly(B);
end
Pimin = min(P.min,B.min);
Pimax = max(get(P,'max'),get(B,'max'));
Pi = trim(P,[Pimin,Pimax]);
B = trim(B,[Pimin,Pimax]);
Pi.coef(S.subs{:},:) = B.coef;
Pi = trim(Pi);
case '{}' % change one coefficient
if (length(S.subs) > 1)
error('left-hand side subscript must be a single integer');
end
index = S.subs{1};
if (length(index) ~= 1 | index ~= round(index))
error('left-hand side subscript must be a single integer');
end
Pmax = get(P,'max');
Pi = P;
if (index > Pmax) % add coefficient beyond last one
Pi.coef = cat(3,Pi.coef,zeros(size(Pi.coef,1),size(Pi.coef,2),index-Pmax-1),B);
elseif (index < P.min) % add coefficient before first one
Pi.coef = cat(3,B,zeros(size(Pi.coef,1),size(Pi.coef,2),P.min-index-1),Pi.coef);
Pi.min = index;
else % replace existing coefficient
Pi.coef(:,:,index - Pi.min + 1) = B;
end
Pi = trim(Pi);
otherwise
error('this should not happen')
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -