Handling wave data point as $wave in a function
Erik_Kran
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
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).
August 20, 2018 at 09:46 am - Permalink
In reply to If the wave doesn't already… by JimProuty
Thank you very much. And also thanks for [ vs ().
I do not understand why one need to copy the wave. In a macro, it is not necessary. Would you know why it changed?
August 20, 2018 at 10:28 am - Permalink
In reply to Thank you very much. And… by Erik_Kran
Execute this:
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.
August 20, 2018 at 10:34 am - Permalink
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):
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:
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
August 20, 2018 at 11:15 am - Permalink