{"id":511,"date":"2023-12-11T07:50:46","date_gmt":"2023-12-11T12:50:46","guid":{"rendered":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/?p=511"},"modified":"2023-12-11T09:12:12","modified_gmt":"2023-12-11T14:12:12","slug":"vacation-fitness-analytics-unveiling-insights-with-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/2023\/12\/11\/vacation-fitness-analytics-unveiling-insights-with-matlab\/","title":{"rendered":"Vacation Fitness Analytics: Unveiling Insights with MATLAB"},"content":{"rendered":"<table style=\"background-color: #e2f0ff\">\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 120px;padding: 3px;vertical-align: middle\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft wp-image-634 size-medium\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2023\/12\/AfiqPortraitZoom-300x248.png\" alt=\"\" width=\"300\" height=\"248\" \/><\/td>\r\n<td style=\"vertical-align: middle;padding: 3px\"><strong>Guest Writer: <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/8450560\">Afiq Azaibi<\/a>\r\n<\/strong>\r\n<div class=\"content\">\r\n<div class=\"SectionBlock first active\">\r\n<div class=\"SD57BF6401\"><span class=\"SD57BF6400\"><span class=\"SD57BF6402\">I\u2019m happy to introduce Afiq Azaibi, a developer on the Charting Team at MathWorks and avid traveler. Afiq\u2019s first contributions to the team have become popular tools for MATLAB users, <\/span><\/span><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/xline.html\"><span class=\"SD57BF6400\"><span class=\"SD57BF6404\">xline<\/span><\/span><\/a><span class=\"SD57BF6400\"><span class=\"SD57BF6402\">\u00a0and <\/span><\/span><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/yline.html\"><span class=\"SD57BF6400\"><span class=\"SD57BF6404\">yline<\/span><\/span><\/a><span class=\"SD57BF6400\"><span class=\"SD57BF6402\">, which create <\/span><\/span><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.chart.decoration.constantline-properties.html\"><span class=\"SD57BF6400\"><span class=\"SD57BF6404\">ConstantLine<\/span><\/span><\/a><span class=\"SD57BF6400\"><span class=\"SD57BF6404\">\u00a0<\/span><\/span><span class=\"SD57BF6400\"><span class=\"SD57BF6402\">objects<\/span><\/span><span class=\"SD57BF6400\"><span class=\"SD57BF6404\">\u00a0<\/span><\/span><span class=\"SD57BF6400\"><span class=\"SD57BF6402\">(R2018b). Today Afiq will introduce two similar features he created for R2023a, <\/span><\/span><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/xregion.html\"><span class=\"SD57BF6400\"><span class=\"SD57BF6404\">xregion<\/span><\/span><\/a><span class=\"SD57BF6400\"><span class=\"SD57BF6402\">\u00a0and <\/span><\/span><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/yregion.html\"><span class=\"SD57BF6400\"><span class=\"SD57BF6404\">yregion<\/span><\/span><\/a><span class=\"SD57BF6400\"><span class=\"SD57BF6402\">, which create <\/span><\/span><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.chart.decoration.constantregion-properties.html\"><span class=\"SD57BF6400\"><span class=\"SD57BF6404\">ConstantRegion<\/span><\/span><\/a><span class=\"SD57BF6400\"><span class=\"SD57BF6402\">\u00a0objects. Afiq has also given us the opportunity to explore his travel data, which has served as inspiration for many of us to venture outside and discover new places.<\/span><\/span><\/div>\r\n<\/div>\r\n<\/div><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n<hr \/>\r\n\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Break free from the everyday grind and indulge in some travel (analysis). I've been fortunate to have the opportunity to go on several spurts of travel and collect some data along the way. Join me in exploring some insights of my modest datasets.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 0 10px 0\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px 4px 0px 0px;padding: 6px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">websave(<span style=\"color: #a709f5\">'travelAndMileageTables.mat'<\/span>,<span style=\"color: #a709f5\">'https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/travelAndMileageTables.mat'<\/span>); <span style=\"color: #008013\">% download file to current directory<\/span><\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">load <span style=\"color: #a709f5\">travelAndMileageTables.mat<\/span><\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px 0px 4px 4px;padding: 0px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">head(tripTbl)<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 878px;height: 167px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2023\/12\/VacationFitnessAnalytics_IMG_1.png\" alt=\"\" width=\"100%\" height=\"167\" \/><\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 0 10px 0\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px;padding: 6px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">head(mileageTbl)<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px 0px 0px 40px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 159px;height: 148px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2023\/12\/VacationFitnessAnalytics_IMG_2.png\" alt=\"\" width=\"159\" height=\"148\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">These two tables are populated from 2 different parts of my life over the past 3 years. The first table denotes all trips that I've taken and the second table is a modified version of my travel distance on foot logged by my phone.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">The question I'm interested in is whether there are any patterns to my foot travel over the past 3 years. Let's take a look at the daily mileage.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 0 10px 0\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px 4px 0px 0px;padding: 6px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">clf;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">ax = axes;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">dailyMileageLine = plot(ax, mileageTbl.Date, mileageTbl.Mileage, <span style=\"color: #a709f5\">'k'<\/span>, <span style=\"color: #a709f5\">'DisplayName'<\/span>, <span style=\"color: #a709f5\">'Daily Mileage'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">l = legend(ax);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">ax.YLabel.String = <span style=\"color: #a709f5\">'Distance of Foot Travel (Miles)'<\/span>;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">fig = ancestor(ax,<span style=\"color: #a709f5\">'figure'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px 0px 4px 4px;padding: 0px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">fig.Position(3) = 1400;<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 1052px;height: 331px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2023\/12\/VacationFitnessAnalytics_IMG_3.png\" alt=\"\" width=\"100%\" height=\"331\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">There are some high mileage times scattered throughout the years. The simplest explanation might be to chock it up to seasonal exercising. We can label seasons by using <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/xregion.html\"><span style=\"font-family: monospace\">xregion<\/span> <\/a>which produces a <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.chart.decoration.constantregion-properties.html\"><span style=\"font-family: monospace\">ConstantRegion<\/span><\/a>. A <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.chart.decoration.constantregion-properties.html\"><span style=\"font-family: monospace\">ConstantRegion<\/span><\/a> object is bounded along one axis and unbounded along the opposite. In the case of <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/xregion.html\"><span style=\"font-family: monospace\">xregion<\/span><\/a>, it is bounded along the x-axis and unbounded along the y-axis.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 0 10px 0\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px 4px 0px 0px;padding: 6px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">numSeasons = 13;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">startDateSeason = datetime(2020, 12, 1);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">seasonDuration = calmonths(3);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><span style=\"color: #0e00ff\">for <\/span>i = 1:numSeasons<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">\u00a0 \u00a0 currRegion = xregion(startDateSeason, startDateSeason + seasonDuration);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><span style=\"color: #0e00ff\">\u00a0 \u00a0 switch <\/span>mod(i,4)<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><span style=\"color: #0e00ff\">\u00a0 \u00a0 \u00a0 case <\/span>1<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">\u00a0 \u00a0 \u00a0 \u00a0 set(currRegion, <span style=\"color: #a709f5\">'FaceColor'<\/span>, <span style=\"color: #a709f5\">'b'<\/span>, <span style=\"color: #a709f5\">'DisplayName'<\/span>, <span style=\"color: #a709f5\">'Winter'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">\u00a0 \u00a0 \u00a0 \u00a0 winterRegion = currRegion;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><span style=\"color: #0e00ff\">\u00a0 \u00a0 \u00a0 case <\/span>2<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">\u00a0 \u00a0 \u00a0 \u00a0 set(currRegion, <span style=\"color: #a709f5\">'FaceColor'<\/span>, <span style=\"color: #a709f5\">'g'<\/span>, <span style=\"color: #a709f5\">'DisplayName'<\/span>, <span style=\"color: #a709f5\">'Spring'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">\u00a0 \u00a0 \u00a0 \u00a0 springRegion = currRegion;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><span style=\"color: #0e00ff\">\u00a0 \u00a0 \u00a0 case <\/span>3<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">\u00a0 \u00a0 \u00a0 \u00a0 set(currRegion, <span style=\"color: #a709f5\">'FaceColor'<\/span>, <span style=\"color: #a709f5\">'y'<\/span>, <span style=\"color: #a709f5\">'DisplayName'<\/span>, <span style=\"color: #a709f5\">'Summer'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">\u00a0 \u00a0 \u00a0 \u00a0 summerRegion = currRegion;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><span style=\"color: #0e00ff\">\u00a0 \u00a0 \u00a0 case <\/span>0<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">\u00a0 \u00a0 \u00a0 \u00a0 set(currRegion, <span style=\"color: #a709f5\">'FaceColor'<\/span>, <span style=\"color: #a709f5\">'r'<\/span>, <span style=\"color: #a709f5\">'DisplayName'<\/span>, <span style=\"color: #a709f5\">'Autumn'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">\u00a0 \u00a0 \u00a0 \u00a0 autumnRegion = currRegion;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><span style=\"color: #0e00ff\">\u00a0 \u00a0 end<\/span><\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">\u00a0 \u00a0 startDateSeason = startDateSeason + seasonDuration;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><span style=\"color: #0e00ff\">end<\/span><\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px 0px 4px 4px;padding: 0px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">legend([dailyMileageLine, winterRegion, springRegion, summerRegion, autumnRegion]);<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 1038px;height: 327px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2023\/12\/VacationFitnessAnalytics_IMG_4.png\" alt=\"\" width=\"100%\" height=\"327\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Comparing all the regions of similar color, it doesn't appear that there's much overlap between activity and the season. Let's remove the seasons and instead highlight when I was traveling. Both <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/xregion.html\"><span style=\"font-family: monospace\">xregion<\/span><\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/yregion.html\"><span style=\"font-family: monospace\">yregion<\/span><\/a> can take in a vector of start and end points so the syntax below will leverage that.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 0 10px 0\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px 4px 0px 0px;padding: 6px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">seasonRegions = findobj(ax, <span style=\"color: #a709f5\">'Type'<\/span>, <span style=\"color: #a709f5\">'ConstantRegion'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">delete(seasonRegions);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px 0px 4px 4px;padding: 0px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">travelRegions = xregion(ax, tripTbl.startDate, tripTbl.endDate, <span style=\"color: #a709f5\">'DisplayName'<\/span>, <span style=\"color: #a709f5\">'Time away from home'<\/span>)<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px 0px 0px 40px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 300px;height: 399px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2023\/12\/VacationFitnessAnalytics_IMG_5.png\" alt=\"\" width=\"300\" height=\"399\" \/><\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 0 10px 0\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px;padding: 6px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">legend([dailyMileageLine travelRegions(1)]);<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 1041px;height: 327px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2023\/12\/VacationFitnessAnalytics_IMG_6.png\" alt=\"\" width=\"100%\" height=\"330\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">The relationship between high mileage days and periods of travel looks a little clearer. The spikes in daily mileage are mostly clustered in the shaded regions but there is still variability within some travel periods. Since the table has the data, let's break down the trips based on whether or not I was on vacation. We can leverage the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.chart.decoration.constantregion-properties.html#mw_3e4fa42e-2870-4bed-a74a-b2ce0c4be570\"><span style=\"font-family: monospace\">SeriesIndex<\/span><\/a> property to depict the two different types of trips as a different series, each sharing a different color.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 0 10px 0\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px 4px 0px 0px;padding: 6px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">delete(travelRegions);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">vacationTravelRegions = xregion(ax, tripTbl.startDate(tripTbl.vacation), tripTbl.endDate(tripTbl.vacation), <span style=\"color: #a709f5\">'SeriesIndex'<\/span>, 1, <span style=\"color: #a709f5\">'DisplayName'<\/span>, <span style=\"color: #a709f5\">'Vacation Travel'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">nonVacationTravelRegions = xregion(ax, tripTbl.startDate(~tripTbl.vacation), tripTbl.endDate(~tripTbl.vacation), <span style=\"color: #a709f5\">'SeriesIndex'<\/span>, 2, <span style=\"color: #a709f5\">'DisplayName'<\/span>, <span style=\"color: #a709f5\">'Nonvacation Travel'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px 0px 4px 4px;padding: 0px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">hLeg = legend([dailyMileageLine, vacationTravelRegions(1), nonVacationTravelRegions(1)]);<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 1039px;height: 327px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2023\/12\/VacationFitnessAnalytics_IMG_7.png\" alt=\"\" width=\"100%\" height=\"354\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Almost all the instances of high daily mileage occur when I'm traveling for vacation (blue regions) rather than non-vacation travel (orange regions). Vacation travel includes days I worked remotely so that 244-day trip in 2021 was actually only 18 days off work.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">To wrap things up, let's add some final touches to the chart. We can use <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/yline.html\"><span style=\"font-family: monospace\">yline<\/span><\/a> to show the different averages for each category and once again leverage the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.chart.decoration.constantline-properties.html#mw_68b47fc6-958c-407f-8ce3-60336f95d3bd\"><span style=\"font-family: monospace\">SeriesIndex<\/span><\/a> to match the color of the regions. The <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.chart.decoration.constantline-properties.html\"><span style=\"font-family: monospace\">ConstantLine<\/span><\/a> which represents the average for when I'm at home can have a <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.chart.decoration.constantline-properties.html#mw_68b47fc6-958c-407f-8ce3-60336f95d3bd\"><span style=\"font-family: monospace\">SeriesIndex<\/span><\/a> of<span style=\"font-family: monospace\"> 'none' <\/span>to indicate that it's not part of any series and will have a neutral color. Two last tweaks we can do are set <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/answers\/320604-how-do-i-prevent-the-legend-from-auto-updating\"><span style=\"font-family: monospace\">AutoUpdate<\/span><\/a> on the legend to <span style=\"font-family: monospace\">'off'<\/span> and set <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.axis.axes-properties.html#budumk7_sep_budumk7-TickDir\"><span style=\"font-family: monospace\">TickDir<\/span><\/a> on the axes to <span style=\"font-family: monospace\">'none'<\/span>. Turning off <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/answers\/320604-how-do-i-prevent-the-legend-from-auto-updating\"><span style=\"font-family: monospace\">AutoUpdate<\/span><\/a> will prevent the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.chart.decoration.constantline-properties.html\"><span style=\"font-family: monospace\">ConstantLine<\/span><\/a> objects from being added to the legend automatically and setting <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.axis.axes-properties.html#budumk7_sep_budumk7-TickDir\"><span style=\"font-family: monospace\">TickDir<\/span><\/a> to<span style=\"font-family: monospace\"> 'none' <\/span>will prevent the axes ticks from appearing making the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.graphics.chart.decoration.constantline-properties.html\"><span style=\"font-family: monospace\">ConstantLine<\/span><\/a> labels easier to read.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 0 10px 0\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px 4px 0px 0px;padding: 6px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">dateIntersections = mileageTbl.Date &gt;= tripTbl.startDate.' &amp; mileageTbl.Date &lt;= tripTbl.endDate.';<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">vacationIdx = any(dateIntersections &amp; tripTbl.vacation.', 2);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">nonvacationIdx = any(dateIntersections &amp; ~tripTbl.vacation.', 2);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">hLeg.AutoUpdate = <span style=\"color: #a709f5\">'off'<\/span>;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">vacationMean = mean(mileageTbl.Mileage(vacationIdx));<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">nonvacationMean = mean(mileageTbl.Mileage(nonvacationIdx));<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">homeMean = mean(mileageTbl.Mileage(~(vacationIdx | nonvacationIdx)));<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">yline(vacationMean, <span style=\"color: #a709f5\">'SeriesIndex'<\/span>, 1, <span style=\"color: #a709f5\">'Label'<\/span>, num2str(vacationMean), <span style=\"color: #a709f5\">'LabelVerticalAlignment'<\/span>, <span style=\"color: #a709f5\">'middle'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">yline(nonvacationMean, <span style=\"color: #a709f5\">'SeriesIndex'<\/span>, 2, <span style=\"color: #a709f5\">'Label'<\/span>, num2str(nonvacationMean), <span style=\"color: #a709f5\">'LabelVerticalAlignment'<\/span>, <span style=\"color: #a709f5\">'middle'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">yline(homeMean, <span style=\"color: #a709f5\">'SeriesIndex'<\/span>, <span style=\"color: #a709f5\">'none'<\/span>, <span style=\"color: #a709f5\">'Label'<\/span>, num2str(homeMean), <span style=\"color: #a709f5\">'LabelVerticalAlignment'<\/span>, <span style=\"color: #a709f5\">'middle'<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\"><\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">ax.Title.String = <span style=\"color: #a709f5\">'I''m more active when I''m away from home'<\/span>;<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">ax.XLim = [datetime(2021, 1, 1) datetime(2024, 2, 1)];<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px 0px 4px 4px;padding: 0px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">ax.TickDir = <span style=\"color: #a709f5\">'none'<\/span>;<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 1016px;height: 341px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2023\/12\/VacationFitnessAnalytics_IMG_8.png\" alt=\"\" width=\"100%\" height=\"367\" \/><\/div>\r\n<h2 style=\"margin: 20px 10px 5px 4px;padding: 0px;line-height: 20px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\"><\/h2>\r\n<h2 style=\"margin: 20px 10px 5px 4px;padding: 0px;line-height: 20px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\">Share your thoughts<\/h2>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">There are a lot of ways ConstantLine (<span style=\"font-family: monospace\">xline<\/span>, <span style=\"font-family: monospace\">yline<\/span>) and ConstantRegion (<span style=\"font-family: monospace\">xregion<\/span>, <span style=\"font-family: monospace\">yregion<\/span>) can be used to enhance your visualizations. We would be happy to hear your thoughts on these new features.<\/div>\r\n<script type=\"text\/javascript\">var css = ''; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2023\/12\/VacationFitnessAnalytics_IMG_4.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>\r\n\r\n\r\n\r\nGuest Writer: Afiq Azaibi\r\n\r\n\r\n\r\nI\u2019m happy to introduce Afiq Azaibi, a developer on the Charting Team at MathWorks and avid traveler. Afiq\u2019s first contributions to the team have become... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/2023\/12\/11\/vacation-fitness-analytics-unveiling-insights-with-matlab\/\">read more >><\/a><\/p>","protected":false},"author":198,"featured_media":601,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14,11,2,20,1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts\/511"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/users\/198"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/comments?post=511"}],"version-history":[{"count":13,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts\/511\/revisions"}],"predecessor-version":[{"id":664,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts\/511\/revisions\/664"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/media\/601"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/media?parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/categories?post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/tags?post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}