Azzera filtri
Azzera filtri

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 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by