Index exceeds matrix dimensions using pca in matlab 2013a

2 次查看(过去 30 天)
here is the sample code:
temp_files = dir([temp_dir '\*.jpg']); im_waves = zeros(size(temp_files,1),2551);
for j1 = 1:size(temp_files,1)
filename = fullfile(temp_dir,temp_files(j1).name);
temp_im = imresize(double(imread(filename)),[50 50]);
% temp_im = imresize((imread(filename)),[50 50]);
[im_waves(j1,:),~] = feature_extraction_phase2(temp_im);
end
mean_waves = mean(im_waves);
centered_waves = im_waves - repmat(mean_waves,[size(temp_files,1) 1]);
[evectors,~, evalues] = princomp(centered_waves);
num_eigenfaces = 50;
evectors = evectors(:, 1:num_eigenfaces); // |the error is index exceeds matrix dimensions|
reduced_output_waves = evectors' * centered_waves';
reduced_input_waves = evectors' * (waves_ip - mean_waves)';
temp_score = arrayfun(@(n) 1 / (1 + norm(reduced_output_waves(:,n) - reduced_input_waves)), 1:size(temp_files,1));
score = [score,temp_score];
i checked with debugger too,
the centered
  2 个评论
Mahdi
Mahdi 2014-5-29
Can you show the error message as well please(so we know which variable the error is in)?
Datti Nagadhara Harini
Index exceeds matrix dimensions.
Error in wavelet_compare (line 28) evectors = evectors(:, 1:num_eigenfaces);

请先登录,再进行评论。

回答(1 个)

Geoff Hayes
Geoff Hayes 2014-7-16
Your code assumes that there are 50 columns in evectors. Why? With the debugger, prior to evaluating
evectors = evectors(:, 1:num_eigenfaces);
in the Command Window type
size(evectors)
and observe the results. It is most likely that the number of columns is less than num_eigenfaces. What you can do instead is
num_eigenfaces = min(size(evectors,2),50);
to use the minimum of the number of columns in evectors and 50. This way you won't encounter the index exceeds matrix dimension error.

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by