matlab中的计时器每隔几分钟重复一段代码 [英] Timer in matlab to repeat segments of code every few minutes

查看:43
本文介绍了matlab中的计时器每隔几分钟重复一段代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码从链接下载 CSV 文件,然后将其保存为格式化文件:

I have the following code which downloads a CSV file from a link and then saves it as a formatted file:

urlwrite('http://xweb.geos.ed.ac.uk/~weather/jcmb_ws/JCMB_2013_Sep.csv','Weather Data.csv');
data= readtext('Weather Data.csv');

我想每 5 分钟下载一次下载此文件.文件中更新后的数据用于脚本的其他部分,因此我还希望这些计算和程序的其他部分每 5 分钟自动执行一次,以更改新文件信息.

I want to download download this file every 5 minutes. The updated data from the file is used in other parts of my script so I also want those calculations and other parts of my program to be automated every 5 minutes with the change in new file information.

matlab 中的计时器功能调用一个函数,我宁愿将其作为循环格式来执行,因为我的计算尚未保存为特定函数.

The timer feature in matlab calls a function and i'd rather do it as a loop format because my calculations aren't already saved as specific functions.

我怎样才能以某种循环或计时器的形式实现这一点?

How can I achieve this as some sort of loop or timer?

推荐答案

最简单的方法可能是放入暂停命令,pause(t) 暂停脚本 t秒,所以你可以

The simplest way might be to put in a pause command, pause(t) pauses the script for t seconds, so you could have

while(1)
    tic
    urlwrite('http://xweb.geos.ed.ac.uk/~weather/jcmb_ws/JCMB_2013_Sep.csv','Weather Data.csv');
    data= readtext('Weather Data.csv');
    % run the rest of the code that you need to run on the data you have downloaded
    T=toc;
    pause(300-T)
end

您可以通过按 ctrl+c 来终止循环,这将停止代码.

You can terminate the loop by pressing ctrl+c, which will stop the code.

希望有帮助

这篇关于matlab中的计时器每隔几分钟重复一段代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆