what is this error "??? Index exceeds matrix dimensions." mease in this code??

조회 수: 3 (최근 30일)
Hi all
i tried to implement this code in matlab ,but i obtained this error"??? Index exceeds matrix dimensions."please help me in solving this error .
close all
nr_classes = 40;
nr_train = 4;
k = 1;
for i = 1:nr_classes
for j = 1:nr_train
if(i<10)
nume=
strcat('remove_smallobjects25\000',num2str(i),'hv',num2str(j),'.bmp');
else
nume = strcat('remove_smallobjects25\00',num2str(i),'hv',num2str(j),'.bmp');
end
imag = double(imread(nume,'bmp'));
imag = imresize(imag,0.05);
TrainingVectors(:,k) = imag(:);
k = k + 1;
end
end
[features]=feature_extractoion_zoingmodification(TrainingVectors);
k = 1;
for i = 1:nr_classes
for j = 1:nr_train
k=k+1;
end
mean_TrainingVectors(:,i) = mean(features(:,k-4:k-1),2);
end
[KL, Dsorted, Vsorted] = Compute_PCA(features)
for dim = 1:length(eigen_values)
energy(dim) = (sum(eigen_values(1:dim)))/(sum(eigen_values(1:length(eigen_values))))*100;
end
nr_features = find(energy ==100);
nr_features = nr_features(1);
train_PCA = KL*mean_TrainingVectors;
train_PCA = train_PCA(1:nr_features,:);
clear TrainingVectors mean_TrainingVectors
k = 1;
for i = 1:nr_classes
for j = nr_train+1:nr_train+1
if(i<10)
nume = strcat('remove_smallobjects25\000',num2str(i),'hv',num2str(j),'.bmp');
else
nume = strcat('remove_smallobjects25\00',num2str(i),'hv',num2str(j),'.bmp');
end
imag = abs(double(imread(nume,'bmp')));
imag = imresize(imag,0.05);
TestVectors(:,k) = imag(:);
k = k + 1;
end
[features]=feature_extractoion_zoingmodification(TestVectors);
end
test_PCA = KL*TestVectors;
test_PCA = test_PCA(1:nr_features,:);
for i = 1:size(test_PCA,2)
for j = 1:size(train_PCA,2)
distance_measure(i,j) = sqrt(sum(abs(test_PCA(:,i)-train_PCA(:,j)).^2));
end
end
[val, poz] = min(dist_City_block,[],2);
labels = [1:nr_classes]';
disp ('recognition score [%]')
score = length(find(poz==labels))/nr_classes * 100

채택된 답변

Image Analyst
Image Analyst 2012년 4월 9일
In this line:
TrainingVectors(:,k) = imag(:);
you never declared TrainingVectors yet, so when you say ":" (meaning "all rows") it doesn't know how many "all" is because TrainingVectors has not been defined yet and doesn't have a set size. You need to preallocate it before either of the two for loops with the zeros() function.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by