I aks question here about my time error I've experienced and someone answer me. the code goes like this
function y = IsBetween5AMand7PM
coder.extrinsic('clock');
time = clock;
current = 3600*time(4) + 60*time(5) + time(6); %seconds passed from the beginning of day until now
morning = 3600*7; %seconds passed from the beginning of day until 7AM
evening = 3600*17; %seconds passed from the beginning of day until 5PM
y = current > morning && current < evening;
end
I tried putting this on simulink with a matlab function block and connected it to display but errors like this occured
Subscripting into an mxArray is not supported.
Function 'MATLAB Function2' (#49.99.106), line 4, column 20: "time(4)"
Undefined function or variable 'current'. The first assignment to a local variable determines its class.
Function 'MATLAB Function2' (#49.340.347), line 7, column 9: "current"
Undefined function or variable 'current'. The first assignment to a local variable determines its class.
Function 'MATLAB Function2' (#49.361.368), line 7, column 30:"current"
Errors occurred during parsing of MATLAB function 'MATLAB Function2'
The main fuction of this block is to identify whether time is between 7AM-5PM to have an output. Please help.
At compile time, Simulink needs to be able to determine the size and datatype of the variables. In your case, it needs to know about time
.
To enable your code to work, insert
time = zeros(1,6);
immediately before the time = clock
line.