How do i deal with argument error?

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by