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
2014-5-29
Can you show the error message as well please(so we know which variable the error is in)?
回答(1 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!