6:37 am

December 21, 2017

Hello,

I want to create a plot with the derivation of existing channel-data.

I send about every 5 minutes the amount of used energy to thingspeak. This is more or less a constant increasing value.

Watching these values in a graph is boring.

I want to display the derivation of these values in a graph.

Example:

Sending each time a value of totally used Kilo-Watt-Hours (kWh):

100,00 ... 100,01 ... 100,02 ... 100,03 ... 100,10 (using the microwave) ... 100,11 ... 100,12 ... 100,12 (main fuse blows) ... 100,12 ...

This should display a const horizontal line with a single peak (microwave) and going back to zero at the end.

I tried this but i does not work:

*[energyData, time] = thingSpeakRead(readChannelID, 'Fields', energyFieldID, 'NumPoints', 100, 'ReadKey', readAPIKey);*

*dydx = diff(energyData(:))./diff(time(:)); % Cannot divide a double array by a duration array.*

And it should be some kind of logarithm. I want to see small changes (e.g. kitchen-light with 60W) as well as big changes (e.g. microwave with 1500W).

Is there a easy way to do so?

Thanks a lot!

1:29 pm

Moderators

March 7, 2017

3:37 pm

December 21, 2017

Hy,

thanks a lot for the really fast response!

I guess its pretty close to a working solution...:

My code is:

[data, time] = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumPoints', 250, 'ReadKey', readAPIKey);

dydx = diff(data(:))./seconds(diff(time(:)));

thingSpeakPlot(time, dydx);

And the result is:

Error using thingSpeakPlot (line 59)

X must be same length as Y.

Error in Create a 2-D line plot 2 (line 25)

thingSpeakPlot(time, dydx);

Can you help me one more time?

10:01 am

Moderators

March 7, 2017

Since dxdy is a difference, there is one less point in that array, compared to the time stamps. After you do the calculation, remove the first point in the time array.

I changed one of your variable names in the code below.

*[data, times] = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumPoints', 250, 'ReadKey', readAPIKey);*

*dydx = diff(data(:))./seconds(diff(times(:)));*

times(1)=[]; %remove one data point for plotting. MATLAB arrays stary at 1, not zero.

*thingSpeakPlot(times, dydx);*

1:59 pm

December 21, 2017

**PERFECT**

Thanks a lot, nice christms gift 🙂

My code looks at the end like this:

*%*

*% Energy - 2 days deviation log*

*%*

*readChannelID = xxx; % public!*

*fieldID = yy;*

*% numOfPoints = 750;*

*% numOfHours = 2;*

*numOfDays = 2;*

*readAPIKey = '';*

*%% Read Data %%*

*% [data, time] = thingSpeakRead(readChannelID, 'Field', fieldID, 'NumPoints', numOfPoints, 'ReadKey', readAPIKey);*

*[data, time] = thingSpeakRead(readChannelID, 'Field', fieldID, 'NumDays',numOfDays);*

*dydx = 100 * (diff(data(:))./seconds(diff(time(:))));*

*numOfPoints = numel(time); % Number of array elements*

*disp(['numOfPoints is: ''', num2str(numOfPoints), '''']);*

*time2 = time(2:numOfPoints,1);*

*whos; % DEBUGGING*

*%% Visualize Data %%*

*thingSpeakPlot(time2, dydx, 'LineWidth',1, 'Color','red', 'YScale','log');*

Most Users Ever Online: 166

Currently Online:

24 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:

Sahil Nair, ahancity, samexpert, Senseworks, h-kasiri, kleifimmaklyModerators: cstapels: 460

Administrators: Hans: 405, lee: 457