Run a function automatically?

조회 수: 4 (최근 30일)
Jonathan Melia
Jonathan Melia 2020년 7월 13일
댓글: Jonathan Melia 2020년 7월 15일
I have a function that when run determines whether or not a ground heat exchanger should be heating or cooling the house by seeing whether the country is in daylight saving time or not. At the moment if i run the overall code this function checks whether it should be hot or cold and then runs as such.
Is there a way for the function to automatically check the state every day, preferably at 2am, so it refreshes when daylight saving time occurs without being prompted?
function Qsign = isitcold()
c = clock;
d = datetime(c(1),c(2),c(3),'TimeZone','Europe/London');
tf = isdst(d);
if tf == 1 %its summer, Q +ve
Qsign = 1;
else %not summer, Q -ve
Qsign = -1;
end
end

채택된 답변

Rohit Anand
Rohit Anand 2020년 7월 14일
You will have to use Task Scedular of windows 10 to do this.
  1. Create a Matlab Script which calls isitCold(). And then Processes the result to do whatever.
  2. Open Start.
  3. Search for Task Schedular.
  4. Right-click the "Task Scheduler Library" branch, and select the New Folder option.
  5. Type a name for the folder. For example, MyTasks. (This step isn't a requirement, but it's a recommended step to keep your tasks separate from the system and apps tasks.). Click OK
  6. Click the Action menu and Select the Create Basic Task option.
  7. In the "Name" field, type a short descriptive name for the task. For example, Notepad Launcher.
  8. In the "Trigger" choose "daily" and Select the time accordingly.
9. Select Start a Program in the "Action" section. You will next be asked to select the script that should run. Do that.
10. Click Finish.
All done!
I have assumed that you use windows 10. But all OS have a task schedular. You should be able to that easily after a small search.
P.S. - This is not really a MATLAB problem as far as I can tell.
  댓글 수: 1
Jonathan Melia
Jonathan Melia 2020년 7월 15일
I do in fact use OS whose task schedular "automator" doesnt seem as user friendly as its windows counterpart but i'll keep researching to try it from my end.
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by