Handling wave data point as $wave in a function

Hi,

I need to create a wave (its name is name) in a function, and to use the data at each position in the array $name(i). In a function, it is not possible to use $name (i), therefore I generated a another wave to do that:

 

Function SSA(name)
String name

Make /O /N=(100) $name

Wave ww=$name

ww[1]=1

End

 

I am not sure it is very efficient. Does somebody would know another way?

Thanks by advance,

Erik

 

If the wave doesn't already exist, then you're making it correctly.

Just in case you are unaware, ww[1] is the second value in the wave; ww[0] is the first.

Also, ww(val) is different than ww[val]. The first uses X scaling to locate a value, the second uses the point number (row number in a 1D wave).

In reply to by Erik_Kran

Execute this:

DisplayHelpTopic "Wave References"

I recommend that you, and anyone else doing Igor programming, read the Programming help file. It will take a few cycles of reading/programming before everything sinks in.

 

 

I do not understand why one need to copy the wave. In a macro, it is not necessary. Would you know why it changed?

 

You don't need to copy the wave in a function if the wave already exists, you only need to create a wave reference (a pointer to the wave):

 

Function SSA(name)
    String name // name of existing wave

    Wave ww=$name

    Variable i, n= numpnts(ww)
    for(i=0; i<n; i+=1 )
        ww[i]= i
    endfor
End

 If it were me, I would rewrite SSA to take wave parameter. the function can be called from a Macro or the command line by using the name of an existing wave:

Macro moo()
    SSAW(ww)
End


Function SSAW(w)
    Wave w // reference to existing wave

    Variable i, n= numpnts(w)
    for(i=0; i<n; i+=1 )
        w[i]= i
    endfor

End