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.
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!
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(:)));
And the result is:
X must be same length as Y.
Error in Create a 2-D line plot 2 (line 25)
Can you help me one more time?
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.
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
Currently Browsing this Page:
Guest Posters: 1
Administrators: Hans, lee