{"id":1497,"date":"2015-09-09T17:54:53","date_gmt":"2015-09-09T21:54:53","guid":{"rendered":"https:\/\/blogs.mathworks.com\/iot\/?p=1497"},"modified":"2016-02-10T22:56:28","modified_gmt":"2016-02-11T03:56:28","slug":"updates-to-the-matlab-analysis-app-with-lots-of-example-code","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/iot\/2015\/09\/09\/updates-to-the-matlab-analysis-app-with-lots-of-example-code\/","title":{"rendered":"Updates to the MATLAB Analysis App with Lots of Example Code"},"content":{"rendered":"
When using the MATLAB Analysis app on ThingSpeak<\/a>, the MATLAB function to represent date and time (datetime<\/em>) allows you to represent points in time. You can also use datetime(‘now’)<\/em>,\u00a0 datetime(‘today’)<\/em>, datetime(‘yesterday’)<\/em>, or datetime(‘tomorrow’)<\/em> to create scalar datetimes at or around the current moment. Check out our documentation for more information about the datetime<\/a><\/em> function.<\/p>\n On ThingSpeak, so far, the datetime<\/em> function returned time set to UTC time zone by default. Starting at 10 am (EDT) on September 10th<\/sup> 2015, the datetime<\/em> function will return date and time set to your account time zone (at https:\/\/thingspeak.com\/account<\/a>). This will allow you to read data from your channel with timestamps zoned to your local time zone instead of UTC.<\/p>\n For example, my account time zone is set to Eastern Time (US & Canada), and when I ran the following MATLAB code at 12:23 pm, I received:<\/p>\n Prior to this change, I would have received:<\/p>\n As you can see, the timestamp is 4 hours ahead of my time zone, which was due to MATLAB returning time in UTC.<\/p>\n This change makes it easier for you to perform time related activities in your time zone. Note that this new feature is available for both thingSpeakRead and thingSpeakWrite functions as well. As an example, consider the following request to read data from the MathWorks Weather Channel:<\/p>\n MATLAB Code:<\/p>\n Output:<\/p>\n With this enhancement, you would no longer have to explicitly specify the time zone of your dates and time to read and write data\u00a0in your time zone.<\/p>\n Here are a few other examples:<\/p>\n Note that, if at present, you are explicitly setting the time zone to your local time zone, you might see unexpected behavior in your code. Here are a few examples, based on support requests we have received:<\/p>\n To fix this, remove the \u201cTimeZone\u201d assignments since time is now returned in your time zone by default, and use the code below:<\/p>\n To fix this, remove the line with the \u201cTimeZone\u201d assignment, and use the code below:<\/p>\n For more information about the datetime<\/em> function refer to the MATLAB documentation<\/a>. If you\u00a0need support, use the\u00a0MATLAB<\/a> section of the ThingSpeak Forum.<\/p>\n","protected":false},"excerpt":{"rendered":" When using the MATLAB Analysis app on ThingSpeak, the MATLAB function to represent date and time (datetime) allows you to represent points in time. You can also use datetime(‘now’),\u00a0… read more >><\/a><\/p>\n","protected":false},"author":148,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[210,60,209,122],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1497"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/users\/148"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/comments?post=1497"}],"version-history":[{"count":8,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1497\/revisions"}],"predecessor-version":[{"id":1709,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1497\/revisions\/1709"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/media?parent=1497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/categories?post=1497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/tags?post=1497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}dt = datetime('now')\r\ndt =\r\n 10-Sep-2015 12:23:35<\/pre>\ndt =\r\n 10-Sep-2015 16:23:35<\/pre>\n
[data, timestamp] = thingSpeakRead(12397);\r\ndisplay(timestamp.TimeZone, 'TimeZone');<\/pre>\n
\r\ndata =\r\n 225.0000\u00a0\u00a0\u00a0 3.8000\u00a0\u00a0 43.9000\u00a0\u00a0 95.8000\r\n 0\u00a0\u00a0 29.9800\u00a0\u00a0\u00a0 4.3000\u00a0\u00a0\u00a0 0.0300\r\ntimestamp =\r\n 10-Sep-2015 16:13:54\r\nTimeZone =\r\n America\/New_York<\/pre>\n
\n
startDateTime = datetime('September 10, 2015 00:00:00')\r\nendDateTime = datetime('September 10, 2015 23:59:59')\r\nreadChannelID = 12397;\r\n[data, timeStamps] = thingSpeakRead(readChannelID, 'DateRange', [startDateTime, endDateTime])<\/pre>\n\n
startDateTime = datetime('September 10, 2015 07:00:00')\r\nendDateTime = datetime('September 10, 2015 21:00:00')\r\nreadChannelID = 12397;\r\n[data, timeStamps] = thingSpeakRead(readChannelID, 'DateRange', [startDateTime, endDateTime])<\/pre>\n\n
[data, timeStamps] = thingSpeakRead(12397, 'Fields', 3, 'NumPoints', 10);\r\nplot(timeStamps, data)<\/pre>\n
\n
% Set the time now to variable dt\r\ndt = datetime('now')\r\n% Assign time zone to UTC since the dt is unzoned by default\r\ndt.TimeZone = 'UTC';\r\n% Convert the timestamp to \u2018America\/New_York\u2019\r\ndt.TimeZone = 'America\/New_York'<\/pre>\n% Set the time now to variable dt\r\ndt = datetime('now')<\/pre>\n\n
% Read data from a channel\r\n[data, timeStamps] = thingSpeakRead(12397);\r\n% Set the timezone to match your zone\r\ntimeStamps.TimeZone = 'America\/New_York';<\/pre>\n
% Read data from a channel\r\n[data, timeStamps] = thingSpeakRead(12397);<\/pre>\n