登录论坛

查看完整版本 : [MATLAB基础] 循环遇到的问题


Juicy
2009-09-23, 22:13
code如下:

Test = cell(1,40);
V = cell(1,40);
L = zeros(1,40);
Accuracy = zeros(1,40);
for i = 1:40
for j = 2:39
Test_i = find(TestLabel(:)==i);
V_i = length(Test_i);
eval(['Test',num2str(i),' = Test_i ;']);
Test{i} = eval(['Test' num2str(i)]);
eval(['V',num2str(i),' = V_i ;']);
V{i} = eval(['V' num2str(i)]);
L(1) = V{1};
cTestLabel = knnclassify(TestFeature, TrainFeature, TrainLabel);
Accuracy(1) = sum(cTestLabel(1:V{1})==TestLabel(1:V{1}))./V{1};
L(j) = L(j-1) + V{j};
Accuracy(j) = sum(cTestLabel(L(j-1)+1:L(j))==TestLabel(L(j-1)+1:L(j)))./V{j};
end
end

前面运行的没有问题,V的结果是正确的。但运行到了L(j) 和Accuracy(j)时,总显示错误信息:??? In an assignment A(I) = B, the number of elements in B and
I must be the same.

在command window里逐步算L(2), L(3),...却不会有问题。

求救啊!!!:mad: