MWARRAY Matrix with multp array result return C#
Afficher commentaires plus anciens
Function Matla -- function [tt,pp,pr] = PCA(X,comp)
where input: X = Matrix; comp int;
and output is
tt = Matrix pp = Matrix pr = Matrix
So I'm not have know use tis dll of the PCA in program C# because have three different Matriz output.
PCAdll.PCAClass test = new PCAdll.PCAClass(); // PCAdll is Dll creat in Matlab
MWNumericArray MatrixInput= null;
MWArray MatrixOut = null;
int comp = 3;
matriz1 = new MWNumericArray(new double[10, 20]);
for (int i = 1; i<5; i++)
for(int j = 1; j<20; j++)
{
MatrixInput[i,j] = j;
}
MatrixOut = test.PCA((MWArray) MatrixInput, comp);
so how to make to use it in C# program
---------------------- Function Funcion Matla -- function [tt,pp,pr] = PCA(X,comp)
function [tt,pp,pr] = PCA(X,comp)
% [tt,pp,pr]=PCA(X,comp);
% comp is the number of principal components
% Here the NIPALS algorithm is used
% pr = percentage explained variance
X0 = X;
m = mean(X);
[a,b] = size(X);
X = X - ones(a,1)*m;
% Centering the matrix
% the first approximation to t is the first
% column in X
stop = 3;
for i = 1:comp
i
av = std(X);
[av2,indx]=sort(av);
t0 = X(:,indx(b));
while stop > 1,
p0 = t0'*X;
p1 = p0/norm(p0);
t1 = X*p1';
if norm(t1-t0) < 0.00005,
tt(:,i) = t1;
pp(i,:) = p1;
stop = 0;
end;
t0 = t1;
end;
stop = 3;
X = X - t1*p1;
end;
pr = (explv(X0,tt,pp))';
%eig = diag(tt'*tt);
%ssum = cumsum(eig);
%pr = 100*ssum/ssum(comp);
Réponses (0)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!