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?

 Akzeptierte Antwort

Jan
Jan am 20 Nov. 2019
Bearbeitet: Jan am 20 Nov. 2019

0 Stimmen

You stop Matlab at the error already by dbstop if error. Then use the debugger to check the sizes of the arrays:
size(zplot)
size(lbl_train)
lbl_train(i)
size(data.marker)
size(data.color)
Which array is the problem?
I guess that lbl_train has an element > 4.

1 Kommentar

It's been solved. I had a problem with the database. I solved it and is running.
Thank you very much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by