ThingSpeak Data Analysis answer is always NaN

17 ビュー (過去 30 日間)
Nipuna
Nipuna 2020 年 7 月 5 日
コメント済み: Nipuna 2020 年 7 月 6 日
When I use following code the answer I receive is always
Average Humidity = NaN
What is the reason? Is there a way to set data type in Channel fields?
readChannelID = 1094383;
% Humidity Field ID
humidityFieldID = 1;
% Channel Read API Key
% If your channel is private, then enter the read API Key between the '' below:
readAPIKey = 'xxxxxxxxxxxxxx'; %removed the API key
% Get humidity data for the last 60 minutes from the MathWorks weather
% station channel. Learn more about the THINGSPEAKREAD function by going to
% the Documentation tab on the right side pane of this page.
humidity = thingSpeakRead(readChannelID,'Fields',humidityFieldID,'NumMinutes',120,'ReadKey',readAPIKey);
% Calculate the average humidity
avgHumidity = mean(humidity);
display(avgHumidity,'Average Humidity');

回答 (1 件)

Christopher Stapels
Christopher Stapels 2020 年 7 月 6 日
If there is no data in the last 120 minutes, this will return empty, and make the average NaN.
humidity = thingSpeakRead(readChannelID,'Fields',humidityFieldID,'NumMinutes',120,'ReadKey',readAPIKey);
You could add a line to check humitidy to be sure there was data read before calculating the average, or increase the time range.
  1 件のコメント
Nipuna
Nipuna 2020 年 7 月 6 日
Thanks for the answer it helped to identify the problem

サインインしてコメントする。

コミュニティ

その他の回答  ThingSpeak コミュニティ

カテゴリ

Help Center および File ExchangePrepare and Analyze Data についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by