Logical indexing requires support of variable-sized arrays, which is currently disabled.

4 ビュー (過去 30 日間)
Hello,how can i fixed this problem
function [P,V,me,l] = pcaproj(D,arg1,arg2)
%PCAPROJ Projects data vectors using Principal Component Analysis.
%
% [P,V,me,l] = pcaproj(D, odim)
% P = pcaproj(D, V, me)
%
% Input and output arguments ([]'s are optional)
% D (matrix) size dlen x dim, the data matrix
% (struct) data or map struct
% odim (scalar) how many principal vectors are used
%
% P (matrix) size dlen x odim, the projections
% V (matrix) size dim x odim, principal eigenvectors (unit length)
% me (vector) size 1 x dim, center point of D
% l (vector) size 1 x odim, the corresponding eigenvalues,
% relative to total sum of eigenvalues
%
% See also SAMMON, CCA.
% Contributed to SOM Toolbox 2.0, February 2nd, 2000 by Juha Vesanto
% Copyright (c) by Juha Vesanto
% http://www.cis.hut.fi/projects/somtoolbox/
% juuso 191297 070200
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
error( nargchk(2, 3, nargin)); % check the number of input arguments
% the data
if isstruct(D),
if strcmp(D.type,'som_map'), D=D.codebook; else D=D.data; end
end
[dlen dim] = size(D);
if nargin==2,
odim = arg1;
% autocorrelation matrix
A = zeros(dim);
me = zeros(1,dim);
for i=1:dim,
me(i) = mean(D(isfinite(D(:,i)),i));
D(:,i) = D(:,i) - me(i);
end
for i=1:dim,
for j=i:dim,
c = D(:,i).*D(:,j); c = c(isfinite(c));
A(i,j) = sum(c)/length(c); A(j,i) = A(i,j);
end
end
% eigenvectors, sort them according to eigenvalues, and normalize
[V,S] = eig(A);
eigval = diag(S);
[y,ind] = sort(abs(eigval));
eigval = eigval(flipud(ind));
V = V(:,flipud(ind));
for i=1:odim, V(:,i) = (V(:,i) / norm(V(:,i))); end
% take only odim first eigenvectors
V = V(:,1:odim);
l = abs(eigval)/sum(abs(eigval));
l = l(1:odim);
else % nargin==3,
V = arg1;
me = arg2;
odim = size(V,2);
D = D-me(ones(dlen,1),:);
end
% project the data using odim first eigenvectors
P = D*V;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

採用された回答

Walter Roberson
Walter Roberson 2017 年 10 月 11 日
Dcol = D(:,i);
dif = isfinite(Dcol);
me(i) = sum(Dcol .* dif) ./ nnz(dif);
D(:,i) = Dcol - me(i);
and change
c = D(:,i).*D(:,j); c = c(isfinite(c));
A(i,j) = sum(c)/length(c); A(j,i) = A(i,j);
to
c = D(:,i).*D(:,j);
cif = isfinite(c);
A(i,j) = sum(c .* cif) ./ nnz(cif);
A(j,i) = A(i,j);

その他の回答 (1 件)

rym mabrouk
rym mabrouk 2017 年 10 月 11 日
thank you it works , i get one more error Could not determine the size of this expression.
for i=0:nbclass-1
h=plot(Pt(i*nt+1:(i+1)*nt,1),Pt(i*nt+1:(i+1)*nt,2),[style(i+1) color(i+1)]);hold on;
end;

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by