Index in position 2 exceeds array bounds.

3 views (last 30 days)
Zain Achmad
Zain Achmad on 31 Aug 2021
Commented: Walter Roberson on 31 Aug 2021
[ciri_latihZ,muZ,sigmaZ] = zscore(ciri_latih);
% pca
[coeff,score_latih,latent,tsquared,explained] = pca(ciri_latihZ);
% inisialisasi variabel kelas_latih
kelas_latih = cell(jumlah_file,1);
% mengisi nama2 sayur pada variabel kelas_latih
for k=1:300
kelas_latih{k} = 'Angry';
end
for k=301:600
kelas_latih{k} = 'Disgust';
end
for k=601:900
kelas_latih{k} = 'Fear';
end
for k=901:1200
kelas_latih{k} = 'Happy';
end
for k=1201:1500
kelas_latih{k} = 'Neutral';
end
for k=1501:1800
kelas_latih{k} = 'Sad';
end
for k=1801:2100
kelas_latih{k} = 'Surprise';
end
% ekstrak PC1 & PC2
PC1 = score_latih(:,1);
PC2 = score_latih(:,2);
PC3 = score_latih(:,3);
PC4 = score_latih(:,4);
PC5 = score_latih(:,5);
% klasifikasi menggunakan knn
Mdl = fitcecoc([PC1,PC2,PC3,PC4,PC5],kelas_latih);
i got some error on line 82 at "PC1 = score_latih(:,1);" it says Index in position 2 exceeds array bounds. and i don't know to solve it, and the program not get that error before
  1 Comment
Walter Roberson
Walter Roberson on 31 Aug 2021
You could get that error if ciri_latih is empty.
For example it might be a global variable that you did not initialize.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!