Multiple Wave Operation

Hi all,

I'm trying to make the following arithmetic operation to 1500 waves, using Igor:

DFS_500_0001Defl = (-1)*DFS_500_0001Defl

All of the waves have the same name, except for the number XXXX, ie., DFS_500_XXXXDefl.

Do you know if there's any generic way to apply this operation to 1500 waves, without needing to type 1500 times the operation changing the number of the wave?

Hope you answer to me soon, thanx

xavier
Sure. All you have to do is create a function to take care of it for you.

Open up a procedure window (eg. the built in procedure window, which you can get by pressing Ctrl-M) and past the following function into the window:

// The following function assumes that all of the waves are in the root data folder.
Function foo()
    Variable n
    String currentWaveName
    Variable numWaves = 1500
    For (n=0; n<numWaves; n+=1)
        sprintf currentWaveName, "DFS_500_%.4dDefl", n
        print currentWaveName
        WAVE currentWave = $(currentWaveName)
        currentWave = (-1)*currentWave 
    EndFor
End


Then, from the Igor command window, type:
foo()
and hit enter.

FWIW, the following should also work, for example should the number of waves be unspecified and/or their existence as waves (rather than variables) be suspect.

Function foo()
  variable n=0
  string cWaveName
  do
    sprintf cWaveName, "DFS_500_%.4dDefl", n
    if (exists($cWaveName)!=1)
      break
    endif
    wave cWave = $cWaveName
    cWave*=-1
    n+=1
  while(1)
  return 0
end


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH