Matlab 误差尺寸不匹配
我的密码突然出错了。我记得昨天我的代码运行得很好,问题是我不知道我更改了代码的哪一部分。我认为我没有改变任何可能导致这个错误的东西。代码如下:Matlab 误差尺寸不匹配,matlab,Matlab,我的密码突然出错了。我记得昨天我的代码运行得很好,问题是我不知道我更改了代码的哪一部分。我认为我没有改变任何可能导致这个错误的东西。代码如下: 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
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中出现错误
CosIndexi,2=ind
编辑:
我试图删除CosIndexi,2=ind;余弦仍然存在相同的误差:,ind=oneskp,1*1000
即使我有这个错误,我仍然有CosDb的值,我不明白为什么
我想我只是改变了imCat的部分,现在我发现了错误。我很沮丧,因为这个错误不知从何而来
感谢您的帮助。@Mumir使用debugger通过函数进行调试,并查看当您将返回值分配给CosIndexi,2时会发生什么。很可能您有一个大于1x1的ind值被分配给CosIndex。如果这是您真正想要的,您必须将CosIndex定义为一个单元格。细胞可以为你做得更好。若你们给单元格分配了可变大小的数组元素,单元格不会抱怨。@hagubear我能把单元格放入单元格吗?因为我将把CosIndex放入单元格CosDb中,请参见上面的代码。这是非常混乱的,我的代码以前工作得很好,我突然得到了这个错误:dbstop如果出错,然后当它停止时,检查ind的大小。@nkjt我试过了,它停止了,ind的大小是1x0,我不理解lol,但是如果我删除CosIndexi,2=ind;余弦:,ind=oneskp,1*1000;尺寸为1x1。我很困惑什么是kp?我看你是通过输入来理解的。