Set Values in Marquee to NaN

Average rating
(2 votes)
Example Use

Adds one menu item per trace to the GraphMarquee menu. Selecting one sets only that trace's values which lie inside the marquee to NaN. Both Y vs X and waveform traces are supported.

No undo is provided.

#pragma rtGlobals=1		// Use modern global access method.
 
#include <Axis Utilities>
 
Menu "GraphMarquee", dynamic
	CommandPerTrace(),/Q, SetMarqueedValuesToNaN()
End
 
Function/S CommandPerTrace()
 
	String menuList=""
	String traceList=TraceNameList("",";",1+4)	// visible traces
	Variable i, n= ItemsInList(traceList)
	for(i=0; i<n; i+= 1)
		String traceName= StringFromList(i,traceList)
		menuList += "Set "+traceName+" to NaN;"
	endfor
 
	return menuList
End
 
 
Function SetMarqueedValuesToNaN()
 
	GetLastUserMenuInfo
	String traceName
	sscanf S_value, "Set %s to NaN", traceName
	String graphName= WinName(0,1)
	Wave/Z wy= TraceNameToWaveRef(graphName,traceName)
	if( !WaveExists(wy) )
		DoAlert 0, "Trace "+traceName+" could not be found"
		return 0
	endif
 
	String hAxis= StringFromList(0,HVAxisList(graphName,1))
	String vAxis= StringFromList(0,HVAxisList(graphName,0))
	GetMarquee/W=$graphName/K $hAxis, $vAxis
	Variable xMin= min(V_right, V_left)
	Variable xMax= max(V_right, V_left)
	Variable yMin= min(V_top, V_bottom)
	Variable yMax= max(V_top, V_bottom)
 
	// make a mask wave indicating points which lie within the marquee
	// then multiply it with the y (and possibly x) wave
	String maskName=UniqueName("mask",1,0)
	Duplicate/O wy, $maskName
	WAVE mask = $maskName
 
	Wave/Z wx = XWaveRefFromTrace(graphName,traceName)
	if( WaveExists(wx) )	// Y vs x
		mask = (wy > yMin) && (wy < yMax) && (wx > xMin) && (wx < xMax) ? NaN : 1
		wx *= mask
	else		// just a waveform, use X scaling
		mask = (wy > yMin) && (wy < yMax) && (pnt2x(wy,p) > xMin) && (pnt2x(wy,p) < xMax) ? NaN : 1
	endif
	wy *= mask
	KillWaves/Z mask
End

Back to top