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?
1 view (last 30 days)
Show older comments
prashanth shyamala
on 23 Mar 2016
Commented: prashanth shyamala
on 23 Mar 2016
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?
0 Comments
Accepted Answer
Ced
on 23 Mar 2016
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
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!