Separate XY Pair into Weekday and Weekend Waves
hrodstein
// 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
End
// 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
endif
if (day == 7)
return 0 // Saturday
endif
return 1
End
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
Legend/C/N=text0/A=LT
End
// 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
End
// 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
endif
if (day == 7)
return 0 // Saturday
endif
return 1
End
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
Legend/C/N=text0/A=LT
End
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
January 13, 2014 at 09:22 am - Permalink
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.
January 15, 2014 at 04:42 pm - Permalink