Error : Number of elements in 'Timestamps' value must be equal to the number of rows of 'Values' value.
3 次查看(过去 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'));
0 个评论
回答(1 个)
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
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
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 Center 和 File Exchange 中查找有关 Visualize Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!