Do something for all waves in a graph
tutor
I have a bunch of waves plotted in a graph (but the waves are situated in distinct data folders). The idea is that I would like to apply a function on all the waves in the plot and not care where they are in the folders.
Is there a way to do that in Igor?
T
Generally, you can work on all waves on a graph by using the TraceNameList operation. This will return the name of every wave on the current graph (you can restrict this to omit hidden waves if you wish). Then, you can use TraceNametoWaveRef in order to link the trace name (a string) to the actual wave. Finally, if you have x-waves, use the XWaveRefFromTrace operation to get the wave reference for the x-wave.
Run a for loop for then number of names in the tracelist to do your operations.
variable i
for (i=0; i<itemsinlist(list); i+=1)
wave ywave = TraceNametoWaveRef("", stringfromlist(i, list, ";")) //trace i from top most graph
wave xwave = XwaveRefFromTrace("", stringfromlist(i, list, ";")) //x wave associated with trace i
// insert code here to do your desired operation (curve fitting, fft, basic math, derivative, area, etc.)
endfor
May 29, 2013 at 06:31 am - Permalink
I was trying to integrate all the curves in the graph, no matter where they are in the data browser. The resulting wave has to keep the number of the original wave (to be able to distinguish) in between in the root folder. I am using now the above code with the integration:
Integrate/METH=1 ywave/X=xwave/D=R_int;DelayUpdate
But I think the R_int will be re-writen after the first curve got integrated. I do not know but the result is just a wave called R_int. how can I keep the original name of the wave?
Thanks for support!
T
May 30, 2013 at 09:35 am - Permalink
One danger here is the event of 2 waves of similar name in different folders (the resultant integrated waves would have the same name and therefore can't be kept in the root folder together).
String dest_wave = yname + "_int" // add _int to name to distinguish from source
Integrate/METH=1 ywave/X=xwave/D=$Dest_Wave;DelayUpdate //use string Dest_Wave to name the destination wave based on the y-wave name.
May 30, 2013 at 12:07 pm - Permalink