![]() |
如何在后台更新MATLAB GUI?
我有一个MATLAB GUI和一个单独的将数据写入文件的应用程序。我希望我的MATLAB GUI定期检查文件,并在更改时更新GUI。
在Java中,我将使用SwingUtils.Timer(sp?)对象执行类似的操作。 MATLAB有计时器功能吗?我可以编写一个Java类并做到这一点,但是想要一个快速而肮脏的演示程序,最好是纯MATLAB。 回答: 您可以使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/timer.html"]TIMER[/URL]函数在MATLAB中创建计时器对象。例如,这创建了一个计时器对象,该对象应在计时器启动后每10秒执行一次[B]myFcn[/B]函数: timerObject = timer('TimerFcn',@myFcn,'ExecutionMode','fixedRate',... 'Period',10.0); 使用功能[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/start.html"]START[/URL]和[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/stop.html"]STOP[/URL]启动和停止计时器。使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/deletetimer.html"]完[/URL]它们后,您还应该始终记得用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/deletetimer.html"]DELETE删除[/URL]它们。您可以在[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f9-38055.html"]MATLAB文档中[/URL]找到有关使用计时器的更多信息。 值得注意的是,如果要在GUIDE GUI中更新轴对象,则需要额外的“欺骗性”才能完成此工作。您必须在GUIDE中更改axes对象的[URL="http://www.mathworks.com/help/matlab/ref/axes-properties.html#prop_HandleVisibility"]HandleVisibility[/URL]属性,或者必须显式获取该句柄。为此,请按以下方式更改timerObject的构造(这假设您的GUIDE生成的GUI中的axis窗口称为axes1): timerData.axes = handles.axes1; timerData.n = 1; % some state needed for the plots. timerObject = timer('TimerFcn',@myFcn,... 'ExecutionMode','fixedRate',... 'Period',10.0,... 'UserData', timerData); 然后在myFcn ,我们需要引用axes对象。特别: function [] = myFcn(timerObj, event) timerData = get(timerObj, 'UserData'); plot(timerData.axes, (1:n)/n, sin(20*2*pi*(1:n)/n)); line( (1:n)/n, cos(20*2*pi*(1:n)/n, 'Parent', timerData.axes); timerData.n = timerData.n + 1; set(timerObj, 'UserData', timerData); end [url=https://stackoverflow.com/questions/985037]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 19:49。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.