Displaying dates instead of minutes in 3 day comparison

5 views (last 30 days)
Hi,
im using the matlab visualization to compare and display my temperature data.
Is there a way to show the date and time instead of the the last 1400 minutes?
% Read temperature data from a ThingSpeak channel for three seperate days
% and visualize the data in a single plot using the PLOT function.
% Channel 12397 contains data from the MathWorks Weather Station, located
% in Natick, Massachusetts. The data is collected once every minute.
% Field 4 contains temperature data.
% Channel ID to read data from
readChannelID = xxx;
% Temperature Field ID
myFieldID = 3;
% One day date range
oneDay = [datetime('yesterday') datetime('today')];
% Channel Read API Key
% If your channel is private, then 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.
temperatureDay1 = thingSpeakRead(readChannelID,'Fields',myFieldID, ...
'dateRange', oneDay, 'ReadKey',readAPIKey);
temperatureDay2 = thingSpeakRead(readChannelID,'Fields',myFieldID, ...
'dateRange',oneDay-days(1),'ReadKey',readAPIKey);
temperatureDay3 = thingSpeakRead(readChannelID,'Fields',myFieldID, ...
'dateRange', oneDay-days(2),'ReadKey',readAPIKey);
% Create array of durations
myTimes1 = minutes(1:length(temperatureDay1));
myTimes2 = minutes(1:length(temperatureDay2));
myTimes3 = minutes(1:length(temperatureDay3));
% Visualize the data
plot(myTimes1,temperatureDay1, myTimes2,temperatureDay2, myTimes3, temperatureDay3);
legend({'Day1','Day2','Day3'});
% datetick('x',13,'keepticks');
xlabel('Minuten');
ylabel('Temperatur');
title('3-Tage Temperatur Vergleich Raum');
greetings

Answers (1)

Christopher Stapels
Christopher Stapels on 10 Jan 2022
Edited: Christopher Stapels on 10 Jan 2022
The temperature example you used is a way to compare three different ranges of times onthe same plot. You can read the timestamps from the channel and use them to plot instead of what is in the example. In thingSpeakRead, you can use the 'outputformat', 'timetable', and then access the timestamps in temperatureDay1.Timestamps.
myData=thingSpeakRead(chid,...'outputformat','timetable');
plot(myData.Timestamps,myData.Var1); % Var1 is the field name. or you can use .(1) for field 1
if your data had drastically different scales, you can use yyaxis right between plot calls to plot on the right axis.
plot(...data1)
yyaxis right
plot(...data2...)
You can also get the times from ThingSpeak with the format
[data,timestamps] = thingSpeakRead(...);
  2 Comments
Heiko Engemann
Heiko Engemann on 11 Jan 2022
Hello,
Do I have to create these 3 arrays and how do I do that?
Should i use hours or days instead of minutes?
Is use this plot line:
%plot(temperatureDay1.Timestamps,temperatureDay1.(1),temperatureDay2.Timestamps,temperatureDay2.(1),temperatureDay3.Timestamps,temperatureDay3.(1));
Heiko Engemann
Heiko Engemann on 11 Jan 2022
wait, after thinking about it, it seems ok how it displays it

Sign in to comment.

Communities

More Answers in the  ThingSpeak Community

Categories

Find more on Read Data from Channel in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!