rsmx.m
来自「matlab高级统计工具箱」· M 代码 · 共 26 行
M
26 行
function xo=rsmx(x)
%function xo=rsmx(x)
%constructs full matrix xo of main effects x, cross terms x1.x2, etc
% and quadratics x1^2, etc. given the effects matrix x
% input : x main effects matrix (n experiments * m main effects)
% output: xo main effects, 2*cross products, quadratics arranged as:
% x1 x2... B(:), where B(:) are the lower triangular cols of B :
% B11
% B12 B22
% B13 B23 B33 so xo will have the form:
%
% xo=[ x1 x2 x3 x1^2 x12 x13 x2^2 x23 x3^2] for 1st row, etc.
[n,m]=size(x);
%xo=zeros(n,(m.^2 +m)/2+m); % set up size of xo
for i=1:n
b1=x(i,:)'*x(i,:); % calc outer product
b2=tril(b1);% lower triangle
B=b2(:)';%form row vector
xo(i,:)=[x(i,:),B];
end
% remove cols of xo that are ALL zero
i=find((xo)==0); % find col #'s of cols which = 0
xo(:,i)=[]; % delete these cols
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?