{"id":1924,"date":"2016-09-25T20:12:57","date_gmt":"2016-09-26T00:12:57","guid":{"rendered":"https:\/\/blogs.mathworks.com\/iot\/?p=1924"},"modified":"2016-09-26T12:37:10","modified_gmt":"2016-09-26T16:37:10","slug":"use-matlab-timetable-to-merge-thingspeak-data-channels","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/iot\/2016\/09\/25\/use-matlab-timetable-to-merge-thingspeak-data-channels\/","title":{"rendered":"Use MATLAB ‘timetable’ to Merge ThingSpeak Data Channels"},"content":{"rendered":"

We released a new version of MATLAB\u00ae<\/sup> and it’s available now for every ThingSpeak<\/a> user. MATLAB R2016b<\/a> includes many new features that make it easy to work\u00a0with time-stamped tabular data, manipulate, compare, and store text data efficiently, and find, fill, and remove missing data.<\/p>\n

With multiple sensors around my house or office, I want to be able to send data to multiple ThingSpeak channels. But, when I want to perform data analysis, I have a hard time working with data from multiple channels. The channels do not have the same time stamps and are out-of-sync with each other.<\/p>\n

With R2016b of MATLAB, I am able to use the new timetable<\/a>\u00a0data container. Once the data is a stored as a timetable, I can perform powerful operations such as retime<\/a>, synchronize<\/a>, and\u00a0rmmissing<\/a>.<\/p>\n

In this example, I have two sensors outside of my office here in Natick, MA. One sensor is a temperature sensor that is sending data to ThingSpeak channel\u00a0163540<\/a>. My other sensor is writing humidity data to channel\u00a0163545<\/a>. Both channels are public. My goal is to plot temperature versus humidity over one time series. To accomplish this, I will use\u00a0timetable<\/a>\u00a0and synchronize<\/a>\u00a0inside of a new\u00a0MATLAB Visualization on ThingSpeak.<\/p>\n

% Read from the temperature channel\r\ntemperatureTT = thingSpeakRead(163540,'Fields',1,'NumPoints',100,'outputFormat','timetable');\r\n\r\n% Read from the humidity channel\r\nhumidityTT = thingSpeakRead(163545,'Fields',1,'NumPoints',100,'outputFormat','timetable');\r\n\r\n% Synchronize two timestables and fill in missing data using linear interpolation\r\nTT = synchronize(temperatureTT,humidityTT,'union','linear')\r\n\r\n% Plot Temperature and Humidity over time\r\nplotyy(TT.Timestamps,TT.Temperature,...\r\n       TT.Timestamps,TT.Humidity);\r\n        \r\ntitle('Temperature and Humidity Synchronized From Two Channels')\r\nxlabel('Temperature and Humidity in Natick, MA')\r\nlegend('Temperature','Humidity')<\/pre>\n

The first part of the script reads in ThingSpeak data from two different channels and stores the data in two timetables. Once the data is stored in a timetable, I am able to take advantage of synchronize<\/a>. With synchronize, I can combine both timetables with one time series and fill in missing data using linear interpolation. This results in a plot that shows my data over time without any missing data. To create the plot, I signed into ThingSpeak<\/a>, selected Apps<\/a>, and created a new MATLAB Visualization with my MATLAB code.<\/p>\n

<\/a><\/p>\n

All ThingSpeak users are able to try this example or explore the other new MATLAB features directly on ThingSpeak. I will leave my temperature (163540<\/a>)\u00a0and humidity (163545<\/a>)\u00a0channels public, so you can try out timetable example without having to connect devices to ThingSpeak.<\/p>\n","protected":false},"excerpt":{"rendered":"

<\/div>\n

We released a new version of MATLAB\u00ae and it’s available now for every ThingSpeak user. MATLAB R2016b includes many new features that make it easy to work\u00a0with time-stamped tabular data,… 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":[126,60,209,122,8,7],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1924"}],"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=1924"}],"version-history":[{"count":5,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1924\/revisions"}],"predecessor-version":[{"id":1934,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1924\/revisions\/1934"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/media?parent=1924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/categories?post=1924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/tags?post=1924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}