Sum query with non-periodic data | MATLAB | 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
Sum query with non-periodic data
No permission to create posts
August 25, 2015
9:49 am
Avatar
jesjimher
New Member
Members
Forum Posts: 1
Member Since:
August 25, 2015
sp_UserOfflineSmall Offline

Hi

I'm posting energy measurements to a channel feed that are not periodic, I mean, one hour there may be 10 values, but the next one there may be 50 or 100. The problem comes when I want to calculate daily totals, because something like this:

api.thingspeak.com?sum=daily

returns meaningless values. The reason is that sum simply adds all the values inside each day, and so days with a lot of measurements have higher values than days with fewer.

Is there's some way to calculate a sum taking into account the "distance" between measurements? Graphically speaking, I would need the area under the line chart, not just the sum of the values.

August 25, 2015
8:10 pm
Avatar
Rob Purser
Natick, MA

MathWorks
Members
Forum Posts: 46
Member Since:
August 22, 2015
sp_UserOfflineSmall Offline

I have a similar channel. You can do this in a MATLAB Analysis function:

% Get the data
[data,ts] = thingSpeakRead(32188,'NumMinutes',60);

% Calculate the number of minutes for each value (the weight)
weights = minutes(diff(ts));

% Discard the last data point (because you don't know its weight)
data(end) = [];

% Need to use "dot product" operator (.*), since MATLAB default is
% "cross product" operator.
sum(data .* weights)

Senior Development Manager for IoT and Hardware Interfacing for MATLAB at MathWorks.  Visit ThingSpeak.com to explore the IoT Analytic platform that speaks MATLAB made for engineers and scientists.  You can collect, analyze, and act in 5 minutes or less!

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
18 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

MiguelWap, JamesdinnA, ScottTug, ThomasApesy, RicardoVeque, AlbertRop

Administrators: Hans: 387, lee: 457