I have a string list : A,B,C,D which I would like to use functions on. I'm having trouble understanding how to use the $ if I want to concatenate the string from the list with another string within the function. For example, below I am trying to go through the list and duplicate waves called A_test into A_test_1 and so on. The idea is that the function would run through the string, get the letter, append the appropriate suffix and make a wave out of the new name etc. These waves already exist so I don't have to make them.
The error I get now: "Can't use $ in this way in a function"
Function doit()String list = "A;B;C;D"String theWave
Variable index = 0
thewave = StringFromList(index,list)doDuplicate$thewave +"_test", $thewave +"_test_1"$thewave+"_test_1"[1,] = $thewave+"_test_1"[p-1]Display$thewave +"_test_1"
index += 1while(index <= 3)End
One problem is that your change in thewave never happens inside the loop. Another is that you need wider use of parentheses () around terms. In particular,
$somewave + "_somestring"// this is wrong
$(somewave + "_somestring")// this is correct
should work, although the sense of the assignment with "[1,]" and "[p-1]" is unclear to me (copying the first value into the whole wave can be done easier).
@jjweimer
"$somewave + "_somestring"// this is wrong ": This is not really wrong ("$" has lower priority than "+"), but in general I agree that parentheses help if the order of execution is unclear.
And for curiosity:
Which Igor-Version is CountofItems from? My Igor 6 uses ItemsInList.
Why is the index increased twice?
Here is a different version.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
March 4, 2015 at 09:18 am - Permalink
should work, although the sense of the assignment with "[1,]" and "[p-1]" is unclear to me (copying the first value into the whole wave can be done easier).
@jjweimer
"
$somewave + "_somestring" // this is wrong
": This is not really wrong ("$" has lower priority than "+"), but in general I agree that parentheses help if the order of execution is unclear.And for curiosity:
Which Igor-Version is
CountofItems
from? My Igor 6 usesItemsInList
.Why is the index increased twice?
March 4, 2015 at 03:43 am - Permalink
Yes. I will fix these two mistakes in my posting.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
March 4, 2015 at 09:17 am - Permalink