Plotting a best fit line on ThingSpeak based on data points gathered - Is it possible? | MATLAB IoT Analytics | Forum


Please consider registering

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
Plotting a best fit line on ThingSpeak based on data points gathered - Is it possible?
No permission to create posts
May 8, 2018
1:22 pm
New Member
Forum Posts: 2
Member Since:
April 27, 2018
sp_UserOfflineSmall Offline

Hi all,

I want to plot a best fit (2D) line on ThingSpeak.
I am using ThingSpeak MATLAB visualisations and I edited the program from there by adding in the function "lsline;" to plot the best fit line.
My program is as such:

% TODO - Replace the [] with channel ID to read data from:
readChannelID = 484262;
% TODO - Replace the [] with the Field ID to read data from:
fieldID1 = 1;

%% Read Data %%
[data, time] = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumPoints', 20);

%% Visualize Data %%
thingSpeakPlot(time, data);

However, I have an error code which says this:

To use 'lsline', the following product must be licensed, installed, and enabled:
Statistics and Machine Learning Toolbox
Error in Create a 2-D line plot 3 (line 21)

I wish to do all of the analysis on ThingSpeak cloud platform, and not have to export the data (out from ThingSpeak) and analyse the trends by uploading data to the actual MATLAB R2018 program.
Is it even possible to plot a best fit line on ThingSpeak itself, based on the data points from my channel? Or can this only be done on the actual MATLAB program?
Also, is it possible to plot a best fit line on MATLAB Analysis instead? (Program above is using MATLAB Visualisation)

May 9, 2018
8:50 pm

Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

If you have a license that includes Statistics and Machine learning, then log into thingspeak using the Mathworks account that has the license. You will then be able to use Isline. There are definitely other ways to fit data using the base MATLAB that is available through ThingSpeak. Such a solution will not require a license.

See the example at The last section at the bottom shows how to use polyfit to do linear regression. Poly fit will also fir to higher order polynomials. There are also functions for fit other types of curves. You can definitely do these operations in ThingSpeak MATLAB Visualizations app or the MATLAB analysis app.

You cannot plot a fit line using MATLAB analysis, but you can determine fit parameters to your data in MATLAB analysis.
The linear regression page shows you how to determine slope and intercept for a line of best fit.
The matrix technique shown will work in MATLAB analysis but you would not be able to visualize our data.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
19 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:

qkpham, SANGAMNATH B, swatiiot,, Romi, Drakan01

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457