Separate XY Pair into Weekday and Weekend Waves

Average rating
(2 votes)

// Demo showing how to split XY waves into weekday and weekend waves
//	DayOfWeek(dt)
//	Returns day of week as a number from 1 (Sunday) to 7 (Saturday)
Function DayOfWeek(dt)
	Variable dt					// Input date/time value
	String shortDateStr = Secs2Date(dt, -1)		// <day-of-month>/<month>/<year> (<day of week>)
	Variable dayOfMonth, month, year, dayOfWeek
	sscanf shortDateStr, "%d/%d/%d (%d)", dayOfMonth, month, year, dayOfWeek
	return dayOfWeek	
// IsWeekday(dt)
// Returns 0 for Saturday and Sunday, 1 for the rest of the week
Function IsWeekday(dt)
	Variable dt					// Input date/time value
	Variable day = DayOfWeek(dt)
	if (day == 1)
		return 0				// Sunday
	if (day == 7)
		return 0				// Saturday
	return 1
Function Demo()	// Demonstrates separating an XY pair into weekday and weekend data
	// Make XY pair with date/time values for X
	Make/D/O/N=1000 xData = Date2Secs(2014, 01, 01) + p*60*60		// Step by one hour
	SetScale d, 0, 0, "dat", xData
	Make/D/O/N=1000 yData = p
	// Split into weekday and weekend data
	Extract xData, xDataWeekday, IsWeekday(xData)
	SetScale d, 0, 0, "dat", xDataWeekday				// Extract does not preserve units
	Extract yData, yDataWeekday, IsWeekday(xData)
	Extract xData, xDataWeekend, !IsWeekday(xData)
	SetScale d, 0, 0, "dat", xDataWeekend				// Extract does not preserve units
	Extract yData, yDataWeekend, !IsWeekday(xData)
	Display /W=(30,53,816,609) yData vs xData
	AppendToGraph yDataWeekday vs xDataWeekday
	ModifyGraph rgb(yDataWeekday)=(0, 0, 65535), offset(yDataWeekday)={0,100}
	AppendToGraph yDataWeekend vs xDataWeekend
	ModifyGraph rgb(yDataWeekend)=(0, 65535, 0), offset(yDataWeekend)={0,200}
	ModifyGraph mode=2, lsize=3

I fixed the incorrect

I fixed the incorrect comment on the isWeekDay function.

John Weeks
WaveMetrics, Inc.

Hello hrodstein, I am trying

Hello hrodstein,

I am trying to incorporate the my date/time wave that includes all time stamps into your code, but the execution doesn't work on my part. How do I make this code automatically scan through my date/time wave and create an output to a new wave containing the 0's,1's? There must be a simple modification that I may have missed on my part. Thank you.

Back to top