如果時間是早上7點到下午5點之間,我能夠成功地制定一個時間表,其中輸出爲1,時間基於我的電腦。然而,週一至週日的日子也基於我的電腦。我無法找到解決方案在週一至週六輸出1,並在週日輸出0。我的代碼如下平日和週末的Matlab代碼
function y = IsBetween5AMand7PM
coder.extrinsic('clock');
time = zeros(1,6);
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塊的matlab函數中。
什麼版本的MATLAB – excaza
@excaza R2015a。 – uhlexxxmartini
請參閱['weekday'](http://www.mathworks.com/help/matlab/ref/weekday.html) – excaza