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

조회 수: 6 (최근 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 커뮤니티

카테고리

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