Storing strings in waves

I am trying to recall strings from a wave. This seems to work OK, so long as the wave was created within the function itself, however, it gives unexpected results when I access the data from another function.

#pragma rtGlobals=1     // Use modern global access method.
Function test()
    make/T/O testTextWave={"text","goes","in","here"}
    print testTextWave
    print testTextWave[0]
End

Function testX()
    wave testTextWave
    print testTextWave
    print testTextWave[0]
End


If you run test(), you get the following output:
•test()
  testTextWave[0]= {"text","goes","in","here"}
  text
•testX()
  testTextWave[0]= {"text","goes","in","here"}
  3.37009e-275


can anyone tell me what I am doing wrong? The testX function can "see" the testTextWave just fine and print it in its entirety, but when asked to produce a single cell, it fails.
mtaylor wrote:


#pragma rtGlobals=1     // Use modern global access method.
Function test()
    make/T/O testTextWave={"text","goes","in","here"}
    print testTextWave
    print testTextWave[0]
End

Function testX()
    wave testTextWave
    print testTextWave
    print testTextWave[0]
End



In your function TestX() you have to declare testtextwave was a text wave using the /T flag, otherwise, Igor will assume that it is numerical.

Function testX()
    wave/T testTextWave
    print testTextWave
    print testTextWave[0]
End
It should be:
Function testX()
    wave/t testTextWave
    print testTextWave
    print testTextWave[0]
End


I don't know why the print testTextWave in the testX version in the original version worked though.
AH, ok! I had a similar issue earlier when dealing with complex variables. Thanks!
variable/c varname


Was required to hold temporary values. This may seem obvious to everyone out there, but it took me hours of reading to figure it out.
here's a followup:

The following function makes a string that I want to feed into another function. I can make the string just fine...
Function/s makeparslist() // makes a string to feed the display command
    wave/t coeffnames
    variable ii,cnum=numpnts(coeffnames)
    string parslist = "pars[0][*]"
    for(ii = 1 ; ii < cnum ; ii += 1)
        parslist += ",pars["+num2istr(ii)+"][*]"
    endfor
    return parslist
End

but I'm not sure how to feed it into the display command
Display makeparslist()


tells me that I am using the wrong datatype, which makes sense... display is expecting a wave, and i've fed it a string... the string contains a list of wavenames in what should be the proper syntax, but I can't seem to bridge the gap here. Is this even possible to do, or do I need to do this a different way? (I have worked out a loop to append traces to the graph one at a time, but thought this would be more elegant.

I ended up solving it in a different way. Shame, I was excited about my concatenated strings.
Don't give up just yet. There is a way to use display + string function, albeit a bit clumsy one:

Execute "Display " + makeparslist()


Execute is for executing strings as commands, but there are often better ways to do things.
mtaylor wrote:
here's a followup: ... I can make the string just fine...
....but I'm not sure how to feed it into the display command
Display makeparslist()



When your string of wavenames is in a semi-colon separated list called ywavelist, where every wave is in the currrent data folder or has explicit path designations, and each wave is a scaled wave, you could also do ...

Display
LinkDisplay#LAppendtoGraph(ywavelist)


In case each y-wave needs to be plotted versus a specific x-wave, you can also use "linking" functions first, and then repeat the above for the proper outcome.

The Execute command is encapsulated in the LinkDisplay functions.

http://www.igorexchange.com/project/LinkDisplay

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
Thanks for the advice! I am using the "execute" command to solve another part of the code at your suggestion and it's working great! As for the string lists, I saw that earlier while reading the manual but I'm not sure how if will help me in this case. It certainly could come in handy later though.