simulink中

时间:2016-02-07 07:19:39

标签: matlab simulink

我在这里问一下我经历的时间错误,有人回答我。代码就像这样

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

我尝试使用matlab功能块将其置于simulink上并将其连接到显示器,但是发生了这样的错误

  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'

该块的主要功能是确定时间是否在7 AM-5PM之间以产生输出。请帮忙。

1 个答案:

答案 0 :(得分:2)

在编译时,Simulink需要能够确定变量的大小和数据类型。在您的情况下,它需要了解time

要使代码生效,请插入

time = zeros(1,6);

time = clock行之前。