I am a total beginner with ENVI/IDL,
how can I insert a variable into a string for naming an output file in a loop?
I am trying to loop a support vector machines classifier with different values and combinations of the parameters i.e. gamma and penalty factor. this is what I was thinking
gamma=1.167
for penalty=25,1000,25
ENVI_DOIT, 'ENVI_SVM_DOIT', DIMS=array, FID=fid , KERNEL_GAMMA=gamma, OUT_NAME='xxx' , PENALTY=penalty, POS=array, ROI_IDS=array
on this OUT_NAME='xxx' I would like to have 'xxx'gammapenalty (with penalty changing with the loop.
Thank you in advance, I know it's very easy question, but the easiest sometime could be obvious for the most and difficult to find it for the beginner.
I think you want something like:
gamma=1.167
for penalty = 25, 1000, 25 do begin
ENVI_DOIT, 'ENVI_SVM_DOIT', DIMS=array, FID=fid, $
KERNEL_GAMMA=gamma, $
OUT_NAME='xxx-' + strtrim(gamma, 2) + '-' + strtrim(penalty, 2), $
PENALTY=penalty, POS=array, ROI_IDS=array
endfor
Look up STRTRIM
in the docs; it is a helpful routine to convert to a string and remove whitespace (the 2 means remove both leading and trailing whitespace).
By the way, I would probably specify OUT_NAME
using format codes, but those might be more complicated for you unless you are already familiar with the C format codes:
OUT_NAME=string(gamma, penalty, format='(%"xxx-%0.3f-%04d")'), $