フィルターのクリア

Index exceeds matrix dimensions using pca in matlab 2013a

2 ビュー (過去 30 日間)
Datti Nagadhara Harini
Datti Nagadhara Harini 2014 年 5 月 29 日
回答済み: Geoff Hayes 2014 年 7 月 16 日
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
Datti Nagadhara Harini 2014 年 7 月 15 日
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 Center および File ExchangeDimensionality 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