How to access and save individual wave from TraceNameToWaveRef("", traceName)
supra
Usually I drag one of the trace (trace 2 ) to the other and use the code of by "Rgerkin" and then I have two trace in a single graph.
Now when I use "tracename" and use TraceNameToWaveRef("", traceName) and generate y wave and x wave (yw and xw).
Since it is in a loop it access the traces trace1 and trace 2 sequentially and thereby the last yw and xw is always from trace 2.
How I can save the trace 1 in an another variable or use a array function to save the trace1 : xw and yw (say yw1 and xw1) and then can save the trace from the 2nd trace : xw2 and yw2 and then I can do the required subtraction yw=yw2-yw1.
Although in my case the x a values are same (although x waves names are different)..but in case I have a situation whether the x values are different ( point by point ) .., just curious to know ..is it possible to plot yw or I have to interpolate or have to choose either xw1 or xw2 to plot yw ?
String list = TraceNameList("", ";", 1)
String traceName
Variable index = 0
do
traceName = StringFromList(index, list)
if (strlen(traceName) == 0)
break // No more traces.
endif
wave yw = TraceNameToWaveRef("", traceName)
wave xw = XWaveRefFromTrace("", traceName)
------------------
?? need to save in a array yw1 and yw2
---------------
index += 1
while(1)
end
// Want to do the subtraction
yw=yw2-yw1
String traceName
Variable index = 0
do
traceName = StringFromList(index, list)
if (strlen(traceName) == 0)
break // No more traces.
endif
wave yw = TraceNameToWaveRef("", traceName)
wave xw = XWaveRefFromTrace("", traceName)
------------------
?? need to save in a array yw1 and yw2
---------------
index += 1
while(1)
end
// Want to do the subtraction
yw=yw2-yw1
String list = TraceNameList("", ";", 1)
String traceName
Variable index = 0
traceName = StringFromList(0, list)
if (strlen(traceName) == 0)
DoAlert 0, "No YW1"
return -1
endif
wave yw1 = TraceNameToWaveRef("", traceName)
wave xw1 = XWaveRefFromTrace("", traceName)
traceName = StringFromList(1, list)
if (strlen(traceName) == 0)
DoAlert 0, "No YW2"
return -1
endif
wave yw2 = TraceNameToWaveRef("", traceName)
wave xw2 = XWaveRefFromTrace("", traceName)
index += 1
// probably need to make this more general...
Duplicate/O yw1, MyNewWave
// Want to do the subtraction
MyNewWave=yw2-yw1
end
If you *really* want a loop, you will need to make a wave wave (look up the Make command and read about Make/WAVE). In the loop, fill in the wave wave with references to the waves you want.
By the way, the second igor tag needed to be slash-igor to close the code segment.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 18, 2012 at 09:18 am - Permalink
Yes I corrected the tag..thanks
June 18, 2012 at 01:03 pm - Permalink
Next, choose one wave as the basis for your for loop (assuming they have different intervals). For example, I am going to choose xw1. For each value of xw1 in this range (10-40 for the above example numbers), you will need to use interp on yw2. If you always have the case where the intervals of xw1 and xw2 are scalar multiples of eachother, you can avoid using interp but always having the result wave have the same interval spacing as the wave with the fewest datapoints (lowest resolution) and just ignoring the extra data points in the other wave.
where i is the current iteration in your for loop covering the range from 10-40 (again for my example numbers).
I'm vaguely aware of a notation involving the ? symbol that applies a math operation to only a section of a wave, but I'm not sure if that can be used in here place of a for loop (considering interp is required).
June 18, 2012 at 01:56 pm - Permalink
June 20, 2012 at 03:36 pm - Permalink
I wanted to show on a panel the name of the wave subtracted : i,e
with what control I can show it, ValueDispaly is only for numeric value not for string, I tried listbox ...also didnt work.
June 20, 2012 at 04:10 pm - Permalink
June 21, 2012 at 06:37 am - Permalink
titlebox box1 title=NewTitleStr
June 21, 2012 at 08:11 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 21, 2012 at 10:01 am - Permalink
The code beneath (part of my bigger program) does the subtraction and works on Graph with two trace...Mainly what I want to do is to have option in subtraction (arithmetic) so that using setvar0 and setvar1 control I can define MyNewWave…for example say MyNewWave=
2(wave0)- wave1
wheresetvar1=wave0
andsetvar1=wave1
which I say typed in the servar box. Now in present condition it is always hardcoded aswave2-wave1
orwave1-wave2
(if checkbox 1 is checked) .If tried to declare setvar as string ...and tried to access setvar value as MyNewWave ( say MyNewWave=2(setvar0)-setvar1..where I say handtyped
setvar2=wave1
How can I have this...Pl find atta..the ipf file and one Graph containing two trace
Menu "Test Subtrac"
"Test SubtractA/1", Panel10()
End
Variable/G
Window Panel10() : Panel
PauseUpdate; Silent 1
NewPanel /W=(80,40,358,280)
titlebox box1, pos={52,70},size={130,20}, title= "wave1-wave2"
Button button1, pos={52,100},size={130,20}, proc=iSubtractTraceButton, title="Subtract Traces"
CheckBox Check1,pos={52,130},size={39,14},title="Reverse",value= 0
SetVariable setvar0 pos={52,150},size={130,20}, value= _STR:"wave0"
SetVariable setvar1 pos={52,170},size={130,20}, value= _STR:"wave1"
EndMacro
Function iSubtractTraceButton(cntl) : ButtonControl
String cntl
Button $cntl
itestsubtract()
End
Function itestsubtract()
String list = TraceNameList("", ";", 1)
String traceName
Variable index = 0
NVAR setvar1
NVAR setvar1
Variable Conf1
ControlInfo /W=Panel10 Check1
Conf1= V_value
traceName = StringFromList(0, list)
if (strlen(traceName) == 0)
DoAlert 0, "No YW1"
return -1
endif
wave yw1 = TraceNameToWaveRef("", traceName)
wave xw1 = XWaveRefFromTrace("", traceName)
traceName = StringFromList(1, list)
if (strlen(traceName) == 0)
DoAlert 0, "No YW2"
return -1
endif
wave yw2 = TraceNameToWaveRef("", traceName)
wave xw2 = XWaveRefFromTrace("", traceName)
index += 1
Duplicate/O yw1, MyNewWave
string NewTitleStr
if (Conf1)
MyNewWave=yw2-yw1
// MyNewWave=setvar0 - setvar1
NewTitleStr =StringFromList(1, list) + " - " + StringFromList(0, list)
// setvar0 = NewTitleStr
// setvar1 = StringFromList(1, list)
else
MyNewWave=yw1-yw2
NewTitleStr =StringFromList(0, list) + " - " + StringFromList(1, list)
endif
titlebox box1, pos={52,70},size={130,20}, title= NewTitleStr
AppendtoGraph MyNewWave vs xw1
display MyNewWave vs xw1
end
June 23, 2012 at 08:10 pm - Permalink
I then copied the procedures that you posted thinking perhaps they contained the SubtractTracesButton procedure, but no, they don't.
It would be much easier if you would provide a self-contained experiment including all necessary procedures. You can do this by either pasting the procedures in the built-in procedure window or adopting (File->Adopt Procedure) a standalone procedure file. To learn about adopting, execute:
I now see that the panel in the SumRay.pxp file is obsolete as it has only one SetVariable. If I run, Panel10 I get a new panel with two SetVariables. But still no SubtractTracesButton procedure.
I also note that your Panel10 macro is missing the End statement.
Finally, here is an implementation of the SubtractTracesButton function:
String panelName
ControlInfo /W=$panelName setVar0
String firstWaveName = S_Value // e.g., "wave0"
Wave firstWave = $firstWaveName // Create wave reference
ControlInfo /W=$panelName setVar1
String secondWaveName = S_Value // e.g., "wave1"
Wave secondWave = $secondWaveName // Create wave reference
Duplicate /O firstWave, MyNewWave
MyNewWave -= secondWave
End
Function SubtractTracesButton(ba) : ButtonControl
STRUCT WMButtonAction &ba
switch( ba.eventCode )
case 2: // mouse up
SubtractTraces(ba.win)
break
case -1: // control being killed
break
endswitch
return 0
End
This would be better named as SubtractWaves because it does not have anything to do with graphs or traces in graphs. But perhaps that is something you intend to implement later.
June 23, 2012 at 07:46 pm - Permalink
June 23, 2012 at 09:32 pm - Permalink
1) How can I "parse" the string typed in a setvar input box ...such that if I type 2*wave0 in setvar0 field...then after parsing it should set S_Value = wave0 i,e the true wavename ..not 2*wave0..while "2" will be set as coeff so that in next stage of subtraction it can do
coeff* wave0-wave1..... is there any builtin parsar in Igor.
2) I want to populate the setvar0 and setvar1 field by the "wave name" that exist in a current trace ( as then I dont have to type...) ..I tried to use
ControlInfo /W=panel10 setVar0
S_Value= traceName
but it does work..
June 23, 2012 at 09:31 pm - Permalink
In regards to setting the value of the setvariable, you do not use ControlInfo.
Instead, use
Setvariable setVar0 value = _STR:tracename
To update a control, use the same commands you used to make it. Note that you only need to include those which you wish to change (I didn't change the position or size above).
June 25, 2012 at 06:08 am - Permalink
indeed your solution
Setvariable setVar0 value = _STR:tracename
works for me very well..now I can list the waves ..
Thank you so much.
July 10, 2012 at 06:51 pm - Permalink