Multiple line plots in MATLAB visualizations | MATLAB IoT Analytics | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Multiple line plots in MATLAB visualizations
No permission to create posts
March 12, 2019
9:36 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 669
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Showing multiple lines on a ThingSpeak plot required the creation of an array. Now that the Visualization functions a deprecated, its actually much easier to plot multiple lines using the MATLAB plot function. In response to some user feedback (thanks), here is an update to the example for plotting three days of temperature from the MathWorks weatherstation.

% Channel ID to read data from
readChannelID = 12397;
% Temperature Field ID
myFieldID = 4;
% One day date range
oneDay = [datetime('yesterday') datetime('today')];
readAPIKey = '';

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'});
xlabel('Minutes');
ylabel('Temperature F');
title('3-Day Temperature Comparison');

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
33 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Matthewdupreez1, sbhunu, pabcstar, johnhutcheson1, madhuhada, dayne

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457