Displaying dates instead of minutes in 3 day comparison

3 views (last 30 days)
Heiko Engemann
Heiko Engemann on 10 Jan 2022
Commented: Heiko Engemann on 11 Jan 2022
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, ...
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);
% datetick('x',13,'keepticks');
title('3-Tage Temperatur Vergleich Raum');

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.
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.
yyaxis right
You can also get the times from ThingSpeak with the format
[data,timestamps] = thingSpeakRead(...);
Heiko Engemann
Heiko Engemann on 11 Jan 2022
wait, after thinking about it, it seems ok how it displays it

Sign in to comment.


More Answers in the  ThingSpeak Community



Community Treasure Hunt

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

Start Hunting!

Translated by