plz explain what does this code do..?

3 次查看(过去 30 天)
[V, D] = eig(cov(M));
[z1 s1] = size(D);
for i=1:1:s1
D1(i)=D(i,i);
end
D2=max(D1(i));
for i=1:1:s1
if D1(i)==D2;
a1 = V(:,i)./sum(V(:,i));
end
end
[z2 s2]=size(ca{1});

采纳的回答

KSSV
KSSV 2021-3-20
[V, D] = eig(cov(M)); % Calculates the eigenvalues and eigenvectors of covariance of matrix M
[z1 s1] = size(D); % gets the size of diagonal eigenvalue matrix D
for i=1:1:s1
D1(i)=D(i,i); % this loop saves doagonal elements i.e. eigenvalues in D1/
end
% The above can be achieved with D1 = diag(D)
D2=max(D1(i)); % Assigns D1(s1) to D2, this is wrong..should be D2 = max(D1)
for i=1:1:s1 % loop for each eigenvector/ eigenvalue
if D1(i)==D2; % if D1 is equal to maxof D1
a1 = V(:,i)./sum(V(:,i)); % normalize the eigen vectors
end
end
[z2 s2]=size(ca{1});

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by