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
2020 年 4 月 5 日
Can you check in your code that whether comfortTier and currState are numeric variables or they have some other datatype?
回答 (1 件)
drummer
2020 年 4 月 5 日
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
参考
カテゴリ
Help Center および File Exchange で Act on Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!