How do i deal with argument error?

1 回表示 (過去 30 日間)
Akshara Viju
Akshara Viju 2020 年 4 月 5 日
コメント済み: Akshara Viju 2020 年 4 月 5 日
I obtain the following error: Check for missing argument or incorrect argument data type in call to function 'sign'.
Error in trial2 (line 28)
if (sign(comfortTier) ~= sign(currState) || comfortTier == 0)
Below is the code:
%% Configuration %%
alertIntervals = [hours(0.25) hours(1) hours(3) hours(6) hours(12) hours(24)];
%% Channel Info %%
% Channel to read humidity difference
channelID = *******;
channelReadKey = '*********';
% Event name and key for the IFTTT WebHooks service
makerEvent = '*****';
makerKey = '**********';
%% Read Data %%
comfortData = thingSpeakRead(channelID, 'ReadKey', channelReadKey, ...
'NumMinutes', minutes(alertIntervals(end)), ...
'Fields', 3, ...
'OutputFormat', 'table');
currState = comfortData.ComfortTier(end);
lastStateChange = [];
%% Use Data %%
% Determine when the last change in state occurred
for i = height(comfortData):-1:1
comfortTier = comfortData.ComfortTier(i);
lastStateChange = i;
if (sign(comfortTier) ~= sign(currState) || comfortTier == 0)
break
end
end
lastChangeTime = comfortData.Timestamps(lastStateChange);
timeSinceChange = datetime('now') - lastChangeTime;
% Create a message for the state report
stateMsg = '';
if sign(currState) > 0
stateMsg = 'humid';
elseif sign(currState) < 0
stateMsg = 'dry';
end
%% Send Alert %%
% Determine if we are close enough to any of the alert intervals to receive an update
alertCountdowns = alertIntervals - timeSinceChange;
% Send notification if we are within 5 minutes following an alert interval
if sum(alertCountdowns <= 0 & alertCountdowns > -1 * minutes(5)) > 0
webwrite(strcat('https://maker.ifttt.com/trigger/', makerEvent, ...
'/with/key/', makerKey), ...
'value1', stateMsg, ...
'value2', char(timeSinceChange, 'hh:mm'));
end
Thanks in advance
  2 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 4 月 5 日
Can you check in your code that whether comfortTier and currState are numeric variables or they have some other datatype?
Akshara Viju
Akshara Viju 2020 年 4 月 5 日
I guess it's numerical value and due to error in my sensor, it's not accepting it. Thank you so much for your help.

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

回答 (1 件)

drummer
drummer 2020 年 4 月 5 日
You can always debug using dbstop in your line you are having errors.
Another way is by getting one value of confortTier and currState and apply sign to each of them separatelly.
like
sign(confortTier)
sign(currState)
sign(confortTier) ~= sign(currState) % Check if it returns either 0 or 1
Do it in your command window.
We are assuming both variables are the same type, right?
Cheers
  1 件のコメント
Akshara Viju
Akshara Viju 2020 年 4 月 5 日
Thank you so much for your help.. I will try this once..and Yes, we are assuming both values are same.

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

カテゴリ

Help Center および File ExchangeAct on Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by