Issue with ErrorBars in Function
mvwilcox
I'm working on displaying error bars on a graph and can't seem to get around this error message: "When executing ErrorBars, the following problem occured: trace is not on graph".
Here is the bit of the function I'm working with:
//get info on the source graph
String yAxisName= StringByKey("YAXIS", TraceInfo(theGraphName, theTraceName,0))
String axType= StringByKey("AXTYPE", AxisInfo(theGraphName,yAxisName))
String EbarStr = "SEM_" + newTraceName[5,strlen(newTraceName)]
//display the first trace or append the traces
strswitch(axType)
case "right":
if (isXY)
AppendToGraph /R=$YAxisName theNewTrace vs newXWave
ErrorBars theNewTrace Y,wave=($EbarStr,$EbarStr)
Edit newXWave
else
AppendToGraph /R=$YAxisName theNewTrace
ErrorBars theNewTrace Y,wave=($EbarStr,$EbarStr)
endif
execute /q StringByKey("SETAXISCMD", AxisInfo(theGraphName,yAxisName))
break
default:
if (isXY)
AppendToGraph theNewTrace vs newXWave
ErrorBars theNewTrace Y,wave=($EbarStr,$EbarStr)
Edit newXWave
else
AppendToGraph theNewTrace
ErrorBars theNewTrace Y,wave=($EbarStr,$EbarStr)
endif
execute /q StringByKey("SETAXISCMD", AxisInfo(theGraphName,yAxisName))
endswitch
String yAxisName= StringByKey("YAXIS", TraceInfo(theGraphName, theTraceName,0))
String axType= StringByKey("AXTYPE", AxisInfo(theGraphName,yAxisName))
String EbarStr = "SEM_" + newTraceName[5,strlen(newTraceName)]
//display the first trace or append the traces
strswitch(axType)
case "right":
if (isXY)
AppendToGraph /R=$YAxisName theNewTrace vs newXWave
ErrorBars theNewTrace Y,wave=($EbarStr,$EbarStr)
Edit newXWave
else
AppendToGraph /R=$YAxisName theNewTrace
ErrorBars theNewTrace Y,wave=($EbarStr,$EbarStr)
endif
execute /q StringByKey("SETAXISCMD", AxisInfo(theGraphName,yAxisName))
break
default:
if (isXY)
AppendToGraph theNewTrace vs newXWave
ErrorBars theNewTrace Y,wave=($EbarStr,$EbarStr)
Edit newXWave
else
AppendToGraph theNewTrace
ErrorBars theNewTrace Y,wave=($EbarStr,$EbarStr)
endif
execute /q StringByKey("SETAXISCMD", AxisInfo(theGraphName,yAxisName))
endswitch
I'd love to learn why this is happening. The error bar waves certainly exist in the root. Can I use the $ operator to reference these waves? Thank you for any help you can provide.
Cheers,
MVW
I presume that theNewTrace is a wave reference in the code above. Then the ErrorBars command is telling Igor to put the error bars on a trace whose name is theNewTrace. But there is no such trace. The trace name is most-likely $NameOfWave(theNewTrace).
For example, assuming this function in the procedure window:
Wave w
Display w
String traceList = TraceNameList("", ";", 1)
String firstTraceName = StringFromList(0, traceList)
Print firstTraceName
// ModifyGraph mode(w)=3 // Wrong, there is no trace named w
ModifyGraph mode($firstTraceName) = 3 // Right
End
Now execute this:
Test(jack)
In the function Test, w is a wave reference. It is not the name of a trace in the graph.
In most cases, you could use $NameOfWave(w) as the trace name. However, this would not work if you have multiple instances of the same wave in the graph.
Note that Display and AppendToGraph take wave references. ModifyGraph and ErrorBars, and others, take trace names.
To keep the distinction clear, I would change the name "theNewTrace" to "theNewWave". Then use one of the techniques shown above (getting the trace name from TraceNameList or using $NameOfWave(w) if you are sure you don't have multiple instances of the same wave in the graph.
February 3, 2012 at 01:55 pm - Permalink
February 3, 2012 at 02:53 pm - Permalink