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!

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?

Gold

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);*

**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: 114

Currently Online: cstapels

16 Guest(s)

Currently Browsing this Page:

1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

Nsneilotof

angieus2

goldiepw11

BinanceoSt

gnarender123@gmail.com

edenderest

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee