Determing Range of a set of values

AndrewWright
Posts: 6
Joined: 2010-07-30
Location: United States

I would like to have a function "range(waveName [, x1,x2])" that emulates the mean function, but would return the difference between the highest and lowest values in the specified set.


Igor's picture
Posts: 335
Joined: 2007-06-29
Location: United States

How about:

Function myRange(inWave,x1,x2)
	Wave inWave
	Variable x1, x2
 
	WaveStats/M=1/Q/R=(x1,x2) inWave
	return V_max-V_min
End


Posts: 906
Joined: 2007-06-21
Location: United States

How about:

Function RangeDif(w, x1, x2)
	Wave w
	Variable x1, x2
 
	Variable wMin = WaveMin(w, x1, x2)
	Variable wMax = WaveMax(w, x1, x2)
	Variable dif = wMax - wMin
 
	return dif
End

I'm not sure which would be faster (and I'm not willing to bet a nickel on it!).


AndrewWright
Posts: 6
Joined: 2010-07-30
Location: United States

Thanks to both!

I was embedding the function into a routine found in the manual "Finding the Mean of Segments of a Wave," using "range" instead of "mean."

It ended up that working with the WaveMax and WaveMin valuations was the easier way to go. I tried to create a value "y_range" separately, but it wasn't taking for whatever reason. Anyway, I got what I needed.


Back to top