referring to wave in a for loop with incremented numbers

IGOR 5.05

I am trying to refer to waves in a for loop so that I can extract 1 number (cell) from the wave and put into a stats wave.
I can't figure out how to name the wave in the loop using the for loop variable i

The below function works fine. But what I want to do is get rid of the "if" statements that explicitly call out the automatically generated names wave_0, wave_1 ...etc
and use a looped wave name generator something like string expression {wave_i = "wave_" + i_string} where {i_string = sprintf i_string,"%.d", i}
so that I can perform Stats[i] = wave_i[0] on each wave loaded.

This is has stumped me for quite a while now. I am sure it is something simple.
My ultimate goal is to perform statistics on 1000's of files - which is unreasonable for the method I use now.
Any help would be greatly appreciated

#pragma rtGlobals=1 // Use modern global access method.

Function LoadDataSet()
wave Stats
variable i
string i_string
string DataDir, Data
KillWaves/A/Z

for (i=0;i<4;i+=1)
if (i==0) // sprintf uses a space for zero... stupid
I_string = "0"
else
sprintf i_string,"%.d", i /// converts number into string
endif
DataDir = "Test"+ i_string
Data = DataDir + ":data.txt"

LoadWave/J/D/W/K=0/V={"\t, "," $",0,0}/L={0,0,0,2,1}/p=home/A=wave_ Data
//loads data and automatically names waves "wave_0, wave_1, wave_2,wave_3" from directories Test0,Test1....

//Below pulls data from the first row and puts into a previously created wave Stats (with open table)
if (i==0)
wave wave_0
Stats[i] = wave_0[0]
endif

if (i==1)
wave wave_1
Stats[i] = wave_1[0]
endif

if (i==2)
wave wave_2
Stats[i] = wave_2[0]
endif

if (i==3)
wave wave_3
Stats[i] = wave_3[0]
endif

endfor

End
I can't believe I figured this out right after I posted this (spent days before)

Added
String WaveNameString

and Added lines for loop

WaveNameString = "wave_" + i_string
wave wave_i = $WaveNameString
Stats[i] = wave_i[0]

Works fine now
//

///////////////////////////////////////////

#pragma rtGlobals=1 // Use modern global access method.

Function LoadDataSet()
wave Stats
variable i, j
string i_string
string DataDir, Data, WaveNameString
KillWaves/A/Z

for (i=0;i<4;i+=1)
if (i==0) // sprintf uses a space for zero... stupid
I_string = "0"
else
sprintf i_string,"%.d", i /// converts number into string
endif
DataDir = "Test"+ i_string
Data = DataDir + ":data.txt"

LoadWave/J/D/W/K=0/V={"\t, "," $",0,0}/L={0,0,0,2,1}/p=home/A=wave_ Data
//loads data and automatically names waves "wave_0, wave_1, wave_2,wave_3" from directories Test0,Test1....

//Below pulls data from the first row and puts into a previously created wave Stats (with open table)
WaveNameString = "wave_" + i_string
wave wave_i = $WaveNameString
Stats[i] = wave_i[0]


endfor

End



You can omit the if-clause if you use sprintf i_string,"%d", i instead of sprintf i_string,"%.d", i.
Cheers, Wolfgang Harneit
You can read about this topic in the help files- copy this command, paste it into Igor's command line and press Enter:

DisplayHelpTopic "Accessing Waves In Functions"

Your case is covered in the topic

DisplayHelpTopic "Wave Accessed Via String Calculated in Function"

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com