如何在Matlab中创建一个级联矩阵,它会给出下面的结果?
[0.01 0.01 error1]
[0.01 0.03 error2]
...
[30 30 error64]
到目前为止,我尝试过的是下面的内容。
C = [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30];
sigma = [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30];
m = zeros(64,3);
for ci = C
for si = sigma
train = svmTrain(X, y, ci, @(x1, x2) gaussianKernel(x1, x2, si));
pred = svmPredict(train, X);
error = mean(double(pred ~= y))
m = [m ; [C,sigma,error]];
end
end
我期待64 X 3列矩阵。
答案 0 :(得分:3)
您提供的代码似乎基本上就是这样。你应该从一个空矩阵开始。
m = []; % Initialize empty result matrix m
for ci = C
for si = sigma
error = % Calculate error here
m = [m ; [C,sigma,error]]; % concatenate new row onto m.
end
end