WaveList based on a range of number
xhou
I'd like to make (and display) a list of waves based on the range of integers (suffix) in the wave name:
say, the names of my waves are as follows: "test_a4_350", "test_a4_351", "test_a4_352", ..., "test_a4_850".
How can I make a list of wavenames that includes only waves from "test_a4_380" to "test_a4_450"?
Thanks very much!
ListOfWaves(380, 450)
to get a string list of wave names ending in values from 380 to 450 and including the end points.
//outputs a string list (semicolon separated) of wave names with suffixes matching vMin & vMax
Function/S ListOfwaves(vMin, vMax)
Variable vMin
Variable vMax
Variable vIndex = 0
Variable vSuffix = 0
Variable vNumItems = 0
Variable vStrLength
String sFullList = ""
String sEditedList = ""
String sListItem = ""
sFullList = WaveList("*", ";", "" )
vNumItems = ItemsInList(sFullList, ";")
for( vIndex = 0; vIndex < ItemsInList(sFullList, ";"); vIndex += 1)
sListItem = StringFromList(vIndex, sFullList, ";")
vStrLength = strlen( sListItem )
vSuffix = str2num( sListItem[vStrLength - 4, vStrLength - 1] )
if( vSuffix >= vMin && vSuffix <= vMax)
sEditedList += sListItem + ";"
endif
endfor
return sEditedList
End
August 27, 2014 at 06:35 am - Permalink
//outputs a string list (semicolon separated) of wave names with suffixes matching vMin & vMax
Function/S ListOfWaves(baseName, vMin, vMax)
String baseName
Variable vMin, vMax
Variable vIndex = 0
String sEditedList = "", sListItem
for( vIndex = vMin; vIndex <= vMax; vIndex += 1)
sprintf sListItem, "%s%d", baseName, vIndex
if (exists(sListItem) == 1)
sEditedList += sListItem + ";"
endif
endfor
return sEditedList
End
ListOfWaves("test_a4_", 380, 450)
August 28, 2014 at 12:13 am - Permalink
Your codes definitely solved my problem! Thanks so much for your generosity and wisdom. I also learned a bit about how to optimize my igor code from reading yours.
August 29, 2014 at 08:23 am - Permalink
One other thing to keep in mind is that both functions operate only on the current folder.
I like kanekaka's solution... a good example of thinking outside the box.
August 29, 2014 at 08:35 am - Permalink