Borrar filtros
Borrar filtros

Index exceeds matrix dimensions using pca in matlab 2013a

2 visualizaciones (últimos 30 días)
Datti Nagadhara Harini
Datti Nagadhara Harini el 29 de Mayo de 2014
Respondida: Geoff Hayes el 16 de Jul. de 2014
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 comentarios
Mahdi
Mahdi el 29 de Mayo de 2014
Can you show the error message as well please(so we know which variable the error is in)?
Datti Nagadhara Harini
Datti Nagadhara Harini el 15 de Jul. de 2014
Index exceeds matrix dimensions.
Error in wavelet_compare (line 28) evectors = evectors(:, 1:num_eigenfaces);

Iniciar sesión para comentar.

Respuestas (1)

Geoff Hayes
Geoff Hayes el 16 de Jul. de 2014
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.

Categorías

Más información sobre Dimensionality Reduction and Feature Extraction en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by