Best Way to Store Variables
patarroyo
Fri, 08/08/2008 - 01:48 pm
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.
Maybe I didn't understand what's really bothering you. Perhaps more explanation is in order.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
August 8, 2008 at 04:09 pm - Permalink
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.
August 9, 2008 at 12:10 am - Permalink
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.
August 10, 2008 at 08:30 pm - Permalink
August 11, 2008 at 12:45 pm - Permalink
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
August 11, 2008 at 02:32 pm - Permalink
August 12, 2008 at 08:26 am - Permalink
For example:
SetDimLabel 0, 0, red, colors
SetDimLabel 0, 1, green, colors
SetDimLabel 0, 2, blue, colors
colors[%red] = 10
colors[%green] = 20
colors[%blue] = 30
August 12, 2008 at 10:11 am - Permalink