Effacer les filtres
Effacer les filtres

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?

3 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

Ced
Ced le 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

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by