Operations with String lists and Waves
gravityhomer
1) Is there an easy way to take the points of a wave and turn them into a string that is a list. And likewise take a string list and turn it into a text wave (or a normal wave using str2num). I usually need to use a do while loop and cycle through the number of points in the wave. Seems like there would be an easier way, to go from a string list to a wave and or the reverse.
2) Is there an easy way to remove the duplicates from a string list?
Thanks!
gh
To go from a wave to a list, I think you would need a loop. However for the reverse you can use a wave assignment statement. For example:
Make/T/N=(ItemsInList(text_string, ";")) text_wave
text_wave = StringFromList(p, text_string, ";")
print text_wave text_wave[0]= {"a","b","c","d","e","f","g"}
May 27, 2009 at 05:31 am - Permalink
Thanks that definitely solves the string to a wave.
The reason why I wish I could easily convert a wave to a string list is that it is really easy to search string lists. Let's say I have a text wave, it is more difficult to search what point, matches a known string.
May 27, 2009 at 07:05 am - Permalink
Have you looked at the FindValue operation? With the /TXOP flag, you can search a text wave for a specific text value. Also, if you're using Igor 6 or above, you can use the Grep operation to do hard core searching of text waves. That's a bit more complicated than using FindValue, but also more powerful, for example if you need to find the same string multiple times. Finally, you could use the Extract operation, but it's less likely that you'd need to use Extract since the first two options work in most situations.
May 27, 2009 at 07:58 am - Permalink
I have used grep very peripherally. Always with /INDX, as I wasn't clear on most of it. But that FindValue looks awesome, that is pretty much exactly what I am looking for.
Thanks!
gh
May 27, 2009 at 10:39 am - Permalink
"2) Is there an easy way to remove the duplicates from a string list?"
Q: Is there a simple function to eliminate duplicate string elements,
as in "11-4;11-6;11-6;" -> "11-4;11-6;"
Thanks
December 8, 2010 at 01:44 pm - Permalink
String theListStr
String retStr = ""
variable ii
for(ii = 0 ; ii < itemsinlist(theListStr) ; ii+=1)
if(whichlistitem(stringfromlist(ii , theListStr), retStr) == -1)
retStr = addlistitem(stringfromlist(ii, theListStr), retStr, ";", inf)
endif
endfor
return retStr
End
Usage:
print test
test = removeStringlistduplicates(test)
print test
December 8, 2010 at 05:12 pm - Permalink