{"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":"2026-03-31T18:45:55","modified_gmt":"2026-03-31T22:45:55","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 &#8216;timetable&#8217; to Merge ThingSpeak Data Channels"},"content":{"rendered":"<p>We released a new version of MATLAB and it&#8217;s available now for every <a href=\"https:\/\/thingspeak.com\">ThingSpeak<\/a> user. <a href=\"https:\/\/www.mathworks.com\/products\/new_products\/latest_features.html\">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<p>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<p>With R2016b of MATLAB<sup>\u00ae<\/sup>, I am able to use the new <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/timetable.html\">timetable<\/a>\u00a0data container. Once the data is a stored as a timetable, I can perform powerful operations such as <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/retime.html\">retime<\/a>, <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/synchronize.html\">synchronize<\/a>, and\u00a0<a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/rmmissing.html\">rmmissing<\/a>.<\/p>\n<p>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\u00a0<a href=\"https:\/\/thingspeak.com\/channels\/163540\">163540<\/a>. My other sensor is writing humidity data to channel\u00a0<a href=\"https:\/\/thingspeak.com\/channels\/163545\">163545<\/a>. Both channels are public. My goal is to plot temperature versus humidity over one time series. To accomplish this, I will use\u00a0<a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/timetable.html\">timetable<\/a>\u00a0and <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/synchronize.html\">synchronize<\/a>\u00a0inside of a new\u00a0MATLAB Visualization on ThingSpeak.<\/p>\n<pre class=\"prettyprint lang-matlab\">% 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<p>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 <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/synchronize.html\">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 <a href=\"https:\/\/thingspeak.com\/login\">ThingSpeak<\/a>, selected <a href=\"https:\/\/thingspeak.com\/apps\">Apps<\/a>, and created a new MATLAB Visualization with my MATLAB code.<\/p>\n<p><a href=\"https:\/\/thingspeak.com\/channels\/163540\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter\" src=\"https:\/\/images.thingspeak.com\/plugins\/95335\/26k9B5ajibSMRJwS9R0rlA.png\" width=\"583\" height=\"437\" \/><\/a><\/p>\n<p>All ThingSpeak users are able to try this example or explore the other new MATLAB features directly on ThingSpeak. I will leave my temperature (<a href=\"https:\/\/thingspeak.com\/channels\/163540\">163540<\/a>)\u00a0and humidity (<a href=\"https:\/\/thingspeak.com\/channels\/163545\">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 class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/images.thingspeak.com\/plugins\/95335\/26k9B5ajibSMRJwS9R0rlA.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>We released a new version of MATLAB and it&#8217;s available now for every ThingSpeak user. MATLAB R2016b includes many new features that make it easy to work\u00a0with time-stamped tabular data,&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/iot\/2016\/09\/25\/use-matlab-timetable-to-merge-thingspeak-data-channels\/\">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":8,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1924\/revisions"}],"predecessor-version":[{"id":3572,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1924\/revisions\/3572"}],"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}]}}