Can i compare two channels

4 views (last 30 days)
Vesa Salmi
Vesa Salmi on 17 May 2022
Commented: Vesa Salmi on 20 May 2022
I have lakewater temperature metering buoy. Last year has own channel from may to december. This year measuring starts few weeks ago and they have own channel. Can i compare these two channel like at this example: Showing this day and yesterday and the same period at last year?
  1 Comment
Vesa Salmi
Vesa Salmi on 17 May 2022
By the way... here is this year channel.

Sign in to comment.

Answers (1)

Christopher Stapels
Christopher Stapels on 19 May 2022
You definitely can as long as there is data in your channel. Change the part of the code from days(1) to years(1). your final code will depend on how long you want to read data for.(in this case the span of data is one day).
buoyToday = thingSpeakRead(readChannelID,'Fields',TemperatureFieldID,'dateRange',...
buoyLastYear = thingSpeakRead(readChannelID,'Fields',TemperatureFieldID,'dateRange',...
Then be sure to change the places where temperatureDay1 is referenced to whatever you call the new data. In this case I used buoyToday nad buoyLastYear.
  1 Comment
Vesa Salmi
Vesa Salmi on 20 May 2022
Thank you Christopher.
I got it working but some questions appear: Why year 2021 data is so broken? See attached screenshot.
Here is the code i am using:
% Read temperature data from a two ThingSpeak channel; today temperature from channel 1727534
% and same day last year from channel 1041362.
% The data is collected about once every 70 minute. ( ESP.deepSleep(4294967295))
% Channel ID to read data from
lastyearchannelID = 1041362;
thisyearchannelID = 1727534;
% Temperature Field ID
lastyearFieldID = 1;
thisyearFieldID = 1;
% Channel Read API Key
% If channel is private I will enter the read API key between the '' below:
readAPIKey = '';
% Read Temperature Data. Learn more about the THINGSPEAKREAD function by
% going to the Documentation tab on the right side pane of this page.
lastYear = thingSpeakRead(lastyearchannelID,'Fields',lastyearFieldID, ...
'dateRange', [datetime('today')-years(1)-days(2),datetime('today')-years(1)], 'ReadKey',readAPIKey);
thisYear = thingSpeakRead(thisyearchannelID,'Fields',thisyearFieldID, ...
% Create array of durations
myTimes1 = hours(1:length(lastYear));
myTimes2 = hours(1:length(thisYear));
% Visualize the data
plot(myTimes1,lastYear, myTimes2,thisYear);
ylabel('Lämpötila C');
title('Lennuksen poiju 2021 vs. 2022');

Sign in to comment.


More Answers in the  ThingSpeak Community


Find more on Visualize Data in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!