How to use a string to define a wavename?
finn
I would like to make some operations on a number of waves (wave1, wave2, etc.). For this I want to combine the string “wave” with an incrementing number. The problem I have is that once I want to use the combined string D3wave to redimension the wave the following error message occurs: “inconsistent type for a wave reference” because the name D3wave conflicts with the local variable D3wave. Is there an expression similar to num2str() to tell the program not to use “D3wave” but rather the text that is stored by this string?
code:
Function Test()
String name = "wave"
Variable number = 1
String D3wave = name + num2str(number)
wave D3wave
Redimension/N=(-1,-1,10) D3wave
End
cheers, Finn
$
operator, which converts a string into an object reference. See the help on it with this command:DisplayHelpTopic "Converting a String into a Reference Using $"
In your code, you are trying to use the same variable name for a wave reference and a string. You need a different name for the string that names your wave and the wave itself. I often use the convention that a string holding the name of a wave has the suffix "_name" to keep things clear in my code. For your test code, this modification should work:
String name = "wave"
Variable number = 1
String D3wave_name = name + num2str(number)
Wave D3wave = $D3wave_name
Redimension/N=(-1,-1,10) D3wave
End
October 9, 2011 at 05:00 am - Permalink
October 9, 2011 at 09:13 am - Permalink
cheers,
Finn
October 11, 2011 at 10:20 am - Permalink
Wave D3wave = $D3wave_name
make a copy of the wave under the reference handle $D3wave_name and give it a new name D3wave, or does it simply juggle names around without actually copying the data?
August 16, 2012 at 11:16 am - Permalink
wave D3wave will now point to a wave that is indicated by the string.
For instance lets say we have a wave called Wave0:
wave hello = $string
hello*=2
The math operation directly effects wave0. There is no wave named Hello, it is merely a placeholder to be used inside code.
August 16, 2012 at 11:32 am - Permalink