📄 fac2let.m
字号:
function [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,X,Y,Z]=fac2let(Factors,DimX,Fac,LongForm);
% $ Version 1.02 $ Date 28. July 1998 $ Not compiled $
%
% ----------------------------------------------------
% Convert 'Factors' to component matrices
% ----------------------------------------------------
%
% Copyright
% Claus A. Andersson 1995-1997
% Chemometrics Group, Food Technology
% Department of Food and Dairy Science
% Royal Veterinary and Agricultutal University
% Rolighedsvej 30, T254
% DK-1958 Frederiksberg
% Denmark
%
% Phone +45 35283500
% Fax +45 35283245
% E-mail claus@andersson.dk
%
%
% [A,B,C]=fac2let(Factors,DimX,Fac);
% [A,B,C,D]=fac2let(Factors,DimX,Fac);
% [A,B,C,D,E]=fac2let(Factors,DimX,Fac);
% .....
% [A,B,C,...,Z]=fac2let(Factors,DimX,Fac);
%
% This algorithm applies to the N-way case (2<N<25).
%
% If a fourth input is given a matrix will be calculated where
% the f'th column is the kronecker product of the f'th column
% of each loading matrix. This evidently only applies to models
% where the same number of factors are used for each mode.
if nargin<4
Rp=DimX;
Wp=Fac;
if length(Wp)==1
Wp=ones(1,length(DimX))*Wp;
end
if length(Factors)<sum(DimX.*Wp)
error(' Too many components extracted')
elseif length(Factors)~=sum(DimX.*Wp)
disp([' Inconsistency in input parameters (maybe wrong number of components are extracted)'])
end
Cp=length(Rp(1,:));
Txt='ABCDEFGHIJKLMNOPQRSTUVXYZ';
FIdx0=cumsum([1 Rp(1:Cp-1).*Wp(1:Cp-1)]);
FIdx1=cumsum([Rp.*Wp]);
for c=1:Cp,
str=[Txt(c) '='];
str=[str 'reshape(Factors('];
str=[str num2str(FIdx0(c))];
str=[str ':'];
str=[str num2str(FIdx1(c))];
str=[str '),'];
str=[str num2str(Rp(c))];
str=[str ','];
str=[str num2str(Wp(c))];
str=[str ');'];
%disp(str)
eval(str)
end;
else
if any(Fac~=Fac(1))
error(' The number of factors must be the same in every mode')
end
Fac=Fac(1);
A=zeros(prod(DimX),Fac);
for f=1:Fac
L1=Factors(DimX(1)*(f-1)+1:DimX(1)*f);
if length(DimX)>1
L2=Factors(DimX(1)*Fac+DimX(2)*(f-1)+1:DimX(1)*Fac+DimX(2)*f);
Z=kron(L2,L1);
for i=3:length(DimX)
L1=Factors(sum(DimX(1:i-1)*Fac)+DimX(i)*(f-1)+1:sum(DimX(1:i-1)*Fac)+DimX(i)*f);
Z=kron(L1,Z);
end
else
Z=L1;
end
A(:,f)=Z;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -