Index exceeds the number of array elements (4)
이전 댓글 표시
I'm using a database introduced as a 464x10 matrix and am getting the error ''Index exceeds the number of array elements (4)'' on line:
case 2
scatter(zplot(i,1),zplot(i,2), ...
[data.marker{lbl_train(i)},data.color{lbl_train(i)}], ...
'MarkerFaceColor',data.color{lbl_train(i)});
I can't see the problem as the for-loop is programmed to read 464 elements
clf;clear all; close all;
dbstop if error
BD=xlsread('Excel STIX, Unido - Simplificar','B4:K467');
lbl_train= BD(:,10);
E=BD(:,1);%eslora
M=BD(:,3);%manga
K=BD(:,4);%calado
D=BD(:,5);%desplazamiento
I=[E M K D];
Media=mean(I);
Desv=std(I);
Z=(I.*Media)./Desv;
Sigma=cov(Z);
lambda=eig(Sigma);
[lambda,isort]=sort(lambda,'descend');
[V,L,~]=eig(Sigma);
V=V(:,isort);
L=L(isort,isort);
% energy weighting
csum=0;
for ilamb=1:length(lambda)
p(ilamb,1)=lambda(ilamb)/sum(lambda);
csum=csum+p(ilamb);
c(ilamb,1)=csum;
end
table(lambda,p,c)
figure(1)
clf
hold on
stairs(c,'k');
bar(p);
hold off;
legend({'Accumulative Variance','Individual Variance'},'location','east');
xlabel('Principal modes');
ylabel('Variance ratio');
%% Eigen-Projection
nPC=2;
vPC=1:nPC;
W=V(:,vPC);
%% Zr
Zr=Z*W;
figure(2)
clf
data.legend={'1','2','3','4'};
data.color={'r','b','g','y'};
data.marker={'s','d','o','*'};
zplot=Zr;
for i=1:size(zplot,1)
hold on
switch (nPC)
case 1
scatter(zplot(i,1),0,[data.marker{lbl_train(i)},data.color{lbl_train(i)}],'MarkerFaceColor',data.color{lbl_train(i)});
case 2
scatter(zplot(i,1),zplot(i,2),[data.marker{lbl_train(i)},data.color{lbl_train(i)}],'MarkerFaceColor',data.color{lbl_train(i)});
case 3
scatter3(zplot(i,1),zplot(i,2),zplot(i,3),[data.marker{lbl_train(i)},data.color{lbl_train(i)}],'MarkerFaceColor',data.color{lbl_train(i)});
end
hold off
end
Any ideas?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!