wave name into string
carlosgarzonc
how I display the wavename of a wave as a string ??
I have a wave call "hello" and i want to create another one call "hello_everybody" with the same data points as the one wave call "hello".
example
"hello"=[1,2,3]
duplicate hello, hello2
rename hello2, hello+"_everybody"
killwave hello2
print "hello_everybody"
output: "hello_everybody"=[1,2,3]
* I know that my mistake is in: rename hello2, hello+"_everybody"; because hello is a wave a not a string.
Wave hello
Duplicate/O hello, $("hello"+"_everybody")/WAVE=hello2
print hello2
end
•test()
hello_everybody[0]= {1,2,3}
The symbol "hello2" is a "wave reference" a local name for the global wave. The example is a little silly because the strings are all literal strings. It becomes a real solution to a real problem if the original name is entered via a string, for instance:
string wname
Wave w=$wname
Duplicate/O w, $(wname+"_everybody")/WAVE=hello2
print hello2
end
•test("hello")
hello_everybody[0]= {1,2,3}
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 13, 2010 at 09:56 am - Permalink
I have 100 waves that i need to duplicate and rename with the name of the wave plus "_everybody". That means:
"hello"=[1,2,3]
"jallo"=[1,2,3]
"hola"=[1,2,3]
...
i need to duplicate them and rename them as:
"hello_everybody"=[1,2,3]
"jallo_everybody"=[1,2,3]
"hola_everybody"=[1,2,3]
...
at the end i will end up with 200 waves
that means i have to takeduplicate every string, use the name of every wave as a string add "+everybody" and name the just duplicated wave with this name.
* every wave is different.
the function is defined like
Test(wave) // where the wave is hello=[1,2,3]
at the end i need something call:
Hello_everybody=[1,2,3]
October 13, 2010 at 10:17 am - Permalink
I think this should work ...
string suffix, lowaves
variable ic, nt
string theOne, theNewOne
if (ParamIsDefault(lowaves))
// default is all waves in current data folder
lowaves = WaveList("*",";","")
endif
if (strlen(suffix)==0)
// default suffix
suffix = "_duplicate"
endif
nt = numpnts(lowaves)
if (nt == 0)
return 0
endif
for (ic=0;ic<nt;ic+=1)
theOne = StringFromList(ic,lowaves)
sprintf theNewOne, "%s%s", theOne, suffix
duplicate/O $theOne $theNewOne
endif
return nt
end
Examples uses would be as follows:
Everything in Current Folder
Only Waves Starting with XYZ
HTH
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
October 13, 2010 at 10:24 am - Permalink
nameOfWave
.You can use it like this:
duplicate hello $(nameOfWave(hello)+"_everybody")
A
October 13, 2010 at 11:33 am - Permalink
DisplayHelpTopic "Accessing Global Variables And Waves"
DisplayHelpTopic "Accessing Waves In Functions"
The first is a general discussion of WAVE references and related topics, the second is a more specific discussion of common techniques. Note that the subsection "Wave Accessed Via String Calculated in Function" is similar to your situation.
If your wave names are really different (that is, not really computable) you probably have them in a list. Then you might need to know about the StringFromList function.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 13, 2010 at 02:54 pm - Permalink
//where string "oldname" is the string naming your old wave....
string newstring
newstring= (oldname) + "_Everybody"
rename oldname, $(newstring)
October 14, 2010 at 06:12 pm - Permalink
Be careful! In your example the string 'oldname' is renamed, not the wave.
October 15, 2010 at 02:21 pm - Permalink
duplicate oldname, $(newstring); killwaves oldname
October 15, 2010 at 06:06 pm - Permalink
If you work with string variables that contain wave names, you must use the $ operator in order to access the wave itself:
duplicate $oldname, $newstring; killwaves $oldname
October 16, 2010 at 12:27 am - Permalink
In reply to by awirsing
This works for me. Thanks for this piece of information.
May 11, 2021 at 11:05 am - Permalink