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

4 vues (au cours des 30 derniers jours)
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;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

Réponse acceptée

Walter Roberson
Walter Roberson le 11 Oct 2017
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);

Plus de réponses (1)

rym mabrouk
rym mabrouk le 11 Oct 2017
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;

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by