How do i deal with argument error?

1 view (last 30 days)
Akshara Viju
Akshara Viju on 5 Apr 2020
Commented: Akshara Viju on 5 Apr 2020
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 Comments
Ameer Hamza
Ameer Hamza on 5 Apr 2020
Can you check in your code that whether comfortTier and currState are numeric variables or they have some other datatype?
Akshara Viju
Akshara Viju on 5 Apr 2020
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.

Sign in to comment.

Answers (1)

drummer
drummer on 5 Apr 2020
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 Comment
Akshara Viju
Akshara Viju on 5 Apr 2020
Thank you so much for your help.. I will try this once..and Yes, we are assuming both values are same.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!