我目前正試圖顯示通過串口在Matlab應用程序設計器應用程序中接收到的數據。我受到線性測量儀(〜1 Hz)的糟糕刷新率的困擾。App Designer UI元素的刷新率
測量儀的數值由設置爲30Hz的固定速率計時器更新。 定時器回調中的時間戳記打印顯示,它使用正確的頻率調用。我的電腦非常強大,任務管理器沒有顯示任何高負載提示 - 實際上,MATLAB應用幾乎不消耗CPU時間。它實際上不僅僅是測量儀,而是所有的用戶界面元素。
所以我的猜測 - 或者更好:我的希望 - 是在刷新率上必須有一些硬限制。不過,官方文檔並沒有提供任何有關如何改變這一點的提示。
我的MATLAB版本是R2016b。
所以我的問題(S):
是這個固定R2017a?
如果不是的話:我可以做些什麼,例如擺弄MATLAB內置文件嗎?
這裏有一個MCV示例演示問題:
classdef testapp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
andwatchhowthisstartstospinsmoothlyGaugeLabel matlab.ui.control.Label
andwatchhowthisstartstospinsmoothlyGauge matlab.ui.control.SemicircularGauge
KeepturninghereKnobLabel matlab.ui.control.Label
KeepturninghereKnob matlab.ui.control.Knob
end
properties (Access = private)
tim_the_timer
i = 0;
end
methods (Access = private)
function app = refreshMeter(app, ~,~)
% display timestamp
datestr(now,'HH:MM:SS.FFF')
% update the gauge
app.andwatchhowthisstartstospinsmoothlyGauge.Value = app.i;
app.i = app.i + 1;
if app.i > 100
app.i = 0;
end
end
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
t = timer;
t.TimerFcn = @app.refreshMeter;
t.Period = 0.02;
t.BusyMode = 'drop';
t.ExecutionMode = 'fixedRate';
start(t);
app.tim_the_timer = t;
end
% Close request function: UIFigure
function UIFigureCloseRequest(app, event)
stop(app.tim_the_timer);
delete(app.tim_the_timer);
delete(app);
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
app.UIFigure.CloseRequestFcn = createCallbackFcn(app, @UIFigureCloseRequest, true);
setAutoResize(app, app.UIFigure, true)
% Create andwatchhowthisstartstospinsmoothlyGaugeLabel
app.andwatchhowthisstartstospinsmoothlyGaugeLabel = uilabel(app.UIFigure);
app.andwatchhowthisstartstospinsmoothlyGaugeLabel.HorizontalAlignment = 'center';
app.andwatchhowthisstartstospinsmoothlyGaugeLabel.Position = [275 138 246 15];
app.andwatchhowthisstartstospinsmoothlyGaugeLabel.Text = '... and watch how this starts to spin smoothly';
% Create andwatchhowthisstartstospinsmoothlyGauge
app.andwatchhowthisstartstospinsmoothlyGauge = uigauge(app.UIFigure, 'semicircular');
app.andwatchhowthisstartstospinsmoothlyGauge.Position = [338 168 120 65];
% Create KeepturninghereKnobLabel
app.KeepturninghereKnobLabel = uilabel(app.UIFigure);
app.KeepturninghereKnobLabel.HorizontalAlignment = 'center';
app.KeepturninghereKnobLabel.Position = [119 265 112 15];
app.KeepturninghereKnobLabel.Text = 'Keep turning here...';
% Create KeepturninghereKnob
app.KeepturninghereKnob = uiknob(app.UIFigure, 'continuous');
app.KeepturninghereKnob.Position = [145 314 60 60];
end
end
methods (Access = public)
% Construct app
function app = testapp()
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
編輯:我注意到,當我轉動旋鈕,滑塊規將立即被更新,等於是莫名其妙的能力更高的刷新率絕對存在......但如何啓用它而無需觸摸控制?相應地更新MCV。
這是一個非常有趣的問題!實際上,我認爲你正在經歷一種稱爲「[節流](https://dojotoolkit.org/api/1.10/dojo/throttle.html)」的機制。我注意到它只在更新太頻繁時纔會啓動。舉個例子:如果你將它設置爲每0.16秒更新一次(在我的MATLAB 2017a上),這個動作非常平滑。我會盡力進一步調查...... –