How to use a string to define a wavename?
| finn | October 8, 2011 - 23:24 | ||
|---|---|---|---|
|
Hei, 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() wave D3wave Redimension/N=(-1,-1,10) D3wave cheers, Finn |
|||

Joined: 2011-10-01
Location: United States
You need the
$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:
Joined: 2007-06-21
Location: United States
Also see the help on wave references:
Joined: 2010-10-13
Location: Germany
Thank's very much!
cheers,
Finn
Joined: 2012-04-18
Location: Denmark
sorry if this is thread necromancy, but does this line
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?
Joined: 2011-03-14
Location: United States
It doesn't copy the data, or rename the wave.
wave D3wave will now point to a wave that is indicated by the string.
For instance lets say we have a wave called Wave0:
The math operation directly effects wave0. There is no wave named Hello, it is merely a placeholder to be used inside code.