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

8 次查看(过去 30 天)
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'));

回答(1 个)

Mario Chiappelli
Mario Chiappelli 2019-7-24
编辑:Mario Chiappelli 2019-7-25
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 个评论
Mario Chiappelli
Mario Chiappelli 2019-7-25
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 2019-7-26
[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.

请先登录,再进行评论。

社区

更多回答在  ThingSpeak Community

类别

Help CenterFile Exchange 中查找有关 REST API 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by