我的代码突然出错了。我记得昨天我的代码工作正常,问题是我不知道代码的哪一部分已经改变了。 (我不认为我已经改变了可能导致此错误的任何内容)。这是代码:
file_path = 'D:\Telkomiah\KULIAH\TUGAS AKHIR\Program\Uncontrolled and Controlled Dataset\';
per_all = [];
prompt = 'How many keypoints? ';
kp = input(prompt);
for idfile = 1:700
if idfile < 10
name_file = strcat('00',num2str(idfile),'.jpg');
else
if idfile < 100
name_file = strcat('0',num2str(idfile),'.jpg');
else
name_file = strcat(num2str(idfile),'.jpg');
end
end
name_file
im1 = imread(strcat(file_path,name_file));
gray = rgb2gray(im1);
level = 1;
[desc] = Descriptor(gray,kp);
if idfile < 101
imCat = 1;
elseif idfile > 100 && idfile < 201
imCat = 2;
elseif idfile > 200 && idfile < 301
imCat = 3;
elseif idfile > 300 && idfile < 401
imCat = 4;
elseif idfile > 400 && idfile < 501
imCat = 5;
elseif idfile > 500 && idfile < 601
imCat = 6;
else
imCat = 7;
end
dataset1 = load(strcat('maindataset_',num2str(kp),'.mat'));
[a b] = size(dataset1.dataset(1,:));
CosDb = cell(1,b);
for j = 1:b
datasets = dataset1.dataset{1,j};
category = dataset1.dataset{2,j};
Cosine = pdist2(desc, datasets, 'cosine');
CosineSim = Cosine;
CosIndex = zeros(kp,2);
Count = 0;
SumSimilar = 0;
for i = 1:kp
[k, ind] = min(Cosine(i,:));
if k <= 1
CosIndex(i,1) = k;
SumSimilar = SumSimilar + k;
Count = Count + 1;
else
CosIndex(i,1) = 1;
end
CosIndex(i,2) = ind;
Cosine(:,ind) = ones(kp,1)*1000;
% AvrSim = SumSimilar / Count;
end
% AverageSim{j,1} = AvrSim;
TotalSim{1,j} = SumSimilar;
TotalSim{2,j} = category;
CountKey{1,j} = Count;
CosDb{1,j} = CosIndex;
end
[~, indSim] = sort([TotalSim{1,:}],'ascend');
sortedSim = cell2mat(TotalSim(2,indSim));
per = size(find(sortedSim(:,1:100)==1),2);
per_all = [per_all;per];
end
这是我得到的错误:
订阅的分配维度不匹配。
主测试错误(第75行)
CosIndex(i,2)= ind;
编辑:
我尝试删除CosIndex(i,2) = ind;
并且Cosine(:,ind) = ones(kp,1)*1000;
即使我有这个错误,我仍然有CosDb的价值我不明白为什么
我想我只更改了imCat()
部分,现在我发现了错误。我很沮丧因为这个错误无处不在
谢谢你的帮助。