The command svmtrain in LIBSVM matlab package takes input for values of C and g in quotes as a string value. I want to use the single code svmtrain repetitively by having different values for C and g. But how to do it?

2 次查看(过去 30 天)
the command i want to reuse repetitively was:
svmtrain(Label,instance, * * _' -c 12 -g 2 '_**);
Here how do can i change values of 12 and 2 in a kind of loop continuously?

采纳的回答

Ced
Ced 2016-3-23
What you essentially need to do is concatenate strings (and convert the number into a string). Let's say you want to test the vector c = [ 12 16 20 ] and g = [ 2 3 4 ](one at a time).
You can then create your option-string directly as:
for i = 1:length(c)
opt = [ '-c ' num2str(c(i)) ' -g ' num2str(g(i)) ];
% now call svmtrain
end
or use sprintf
for i = 1:length(c)
opt = sprintf('-c %i -g %i',c(i),g(i));
% now call svmtrain
end
For me, the second option is more readable, especially if you have a lot of options.
Cheers

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by