Best Way to Store Variables

I am writing functions for the purpose of data analysis and curve fitting. I have a variety of string and numeric variables, and currently store most of these in waves. I then reference these waves in my functions, and also use them so that I do not have to reenter information by recalling the values stored in these waves. Is this the best way to store such variables? Or should I be using some kind of global variable instead of storing them in waves? What I have works, I am just not sure if it is the most efficient way to accomplish it, or if there may be a problem with this down the road.
If you are doing curve fitting, then putting the data into waves is the *only* way to do it. That is true for most other types of analysis.

Maybe I didn't understand what's really bothering you. Perhaps more explanation is in order.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:

Maybe I didn't understand what's really bothering you. Perhaps more explanation is in order.

Well, what I was thinking is that I use variables in functions all the time, but they are specific to that function. In order to "save" it so that I can access it later, I have to store it into a wave, and if I want to reference it, pick out the exact spot in the wave where that data resides. If there were a way to store it as some sort of global variable that is accessible outside of just that function, it would be a bit easier to recall stored info in that instead of having to pick a point out of wave, I just have to enter the global variable name. It's really a small thing, and I have the functionality I am after, it's just that my code has recalls like "Points1D=ParameterWave[1]", and I wasn't sure if this was the best way to do things, or if there is some other method that is preferred.
You can create global numeric variables using the Variable/G command and global string variables using String/G. You can read about this by executing:

DisplayHelpTopic "Accessing Global Variables And Waves"

I recommend that you read the entire Programming help file (Windows->Help Files->Programming) or the corresponding chapter in the PDF manual. This will give you the background information you need as well as specifics on using global variables.

Right, I see that I can use global variables. My question now is, which is better, storing information as global variables, or storing them in waves? I lean slightly towards global variables because it is easier to reference them, and then I don't have a whole bunch of little waves clogging up my experiment file. But is there some other advantage? I've skimmed through the help files and am not finding any strong or definitive answers either way. Is it just a matter of style?
As the John says, you have to have all the fit parameters in a wave. However, for the temporary "extra" variables that come in useful to calculate the function I would suggest creating a temporary wave. If you have 10 values you need to hold, you can achieve that using a single wave, which is easy to kill down the track. If you used global variables you would need to create at least 10, which leaves a lot more mess. You just need to keep track of where you store the numbers in the wave.

However, this assumes that the values change from time to time. If they don't, and are unchanging, then I recommend using Constants. Depending on how you specify them these can be accessed from any procedure file. For example:

Static constant GRAVITY = 9.81

Function distance(tt)
variable tt
variable dist = 0.5 * GRAVITY * tt^2
print "The distance a ball drops under gravity in the time specified is: ",dist
return dist
End
Andy, those are very good points. The value of these variables change quite a bit, and now that I think about it, I often times display the waves in a table to see what all the values are at once, rather than having to use a print to the command window for each individual variable. I did not know about constants, that also will come in handy down the road. Thank you all for your help and insight!
You might want to also read the help on Dimension Labels (DisplayHelpTopic "Dimension Labels"). You can use dimension labels to reference a point in a wave using a string instead of the numerical value of the index.

For example:
make/n=3 colors
SetDimLabel 0, 0, red, colors
SetDimLabel 0, 1, green, colors
SetDimLabel 0, 2, blue, colors

colors[%red] = 10
colors[%green] = 20
colors[%blue] = 30