Error : Number of elements in 'Timestamps' value must be equal to the number of rows of 'Values' value.

3 visualizzazioni (ultimi 30 giorni)
I'm coming across this error when I try to execute my code and I'm getting a little bit confused. The purpose of the code is to take data from a particular field from a channel in Thingspeak, analyze it and post the analyzed data to a particular field in another channel. The error is:
Number of elements in 'Timestamps' value must be equal to the number of rows of 'Values' value.
data = thingSpeakRead(ChannelID,'ReadKey',readAPIKey,'Fields',4,'DateRange',[datetime(2019,7,6,14,00,00),datetime('now')]);
%% Analyze Data %%
% Add code in this section to analyze data and store the result in the
% 'analyzedData' variable.
analyzedData = data;
%% Write Data %%
thingSpeakWrite (ChannelID,analyzedData,'WriteKey',writeAPIKey,'Fields',1,'Timestamps',datetime('now'));

Risposte (1)

Mario Chiappelli
Mario Chiappelli il 24 Lug 2019
Modificato: Mario Chiappelli il 25 Lug 2019
I would assume the issue is that you are reading in (for example) 10 data points that match up with 10 date times. You then are writing the 10 analyzed points to thingspeak but you only have one date time that it matches up with.
If you want to store the date times of the incoming points, try something like this:
[data,timestamps] = thingSpeakRead(ChannelID,'ReadKey',readAPIKey,'Fields',4,'DateRange',[datetime(2019,7,6,14,00,00),datetime('now')]);
To fix the problem I would suggest to change the datetime after the 'TimeStamps' to something that reflects the appropriate timestamps of the thingspeak data. So, I would utilize the timestamp variable created above. Try this,
lastTime = length(timestamps);
thingSpeakWrite (ChannelID,analyzedData,'WriteKey',writeAPIKey,'Fields',1,'timestamps',[timestamp(1),timestamp(lastTime)];
  4 Commenti
Mario Chiappelli
Mario Chiappelli il 25 Lug 2019
Do what Walter said and change the 'DateRange' option to 'timestamps'
That was my bad, before you were sending date time values and now you are sending timestamp values. They are the same concept just different input formats.
I changed my code above.
Walter Roberson
Walter Roberson il 26 Lug 2019
[data,timestamps] = thingSpeakRead(681431,'ReadKey',readAPIKey,'Fields',4,'DateRange',[datetime(2019,7,6,14,00,00),datetime('now')]);
%% Analyze Data %%
% Add code in this section to analyze data and store the result in the
% 'analyzedData' variable. This assumes that the number of output rows
% is the same as the number of input rows
analyzedData = data;
thingSpeakWrite (706490,analyzedData,'WriteKey',writeAPIKey,'Fields',1,'Timestamps',timestamps);
If the number of output rows is not the same as the number of input rows, then you need to figure out what meaningful timestamps would be, taking into account that the timestamps must be unique for the channel.

Accedi per commentare.

Community

Più risposte nel  ThingSpeak Community

Categorie

Scopri di più su Visualize Data in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by