5

我目前正試圖顯示通過串口在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。

+0

這是一個非常有趣的問題!實際上,我認爲你正在經歷一種稱爲「[節流](https://dojotoolkit.org/api/1.10/dojo/throttle.html)」的機制。我注意到它只在更新太頻繁時纔會啓動。舉個例子:如果你將它設置爲每0.16秒更新一次(在我的MATLAB 2017a上),這個動作非常平滑。我會盡力進一步調查...... –

回答

1

您應該能夠通過調用refreshMeter回調中的drawnow函數強制刷新。

+0

感謝您的回答。你會如何建議調用'drawnow'?只要在回調中加入這個詞對我來說不會做任何事情,'drawnow update','nocallback','expose' ...... – UnbescholtenerBuerger

+0

從理論上講,只要它放在哪裏都不重要被定期打電話。我不知道爲什麼這不適合你,對不起。 – MrAzzaman

1

我建議以下幾點,以幫助您的問題:

  1. 遵循this它提供了低級別的圖形問題MathWorks公司的解決方案是非常有用的鏈接。它可能與你的顯卡有關。

  2. 以下@MrAzzamans建議,drawnowrefreshdata可以幫助解決您的問題(請記住他們有不同的召喚選項)。

  3. 如果您使用GUIDE,請嘗試更改爲App Designer,看看它是否能解決您的問題。

當在GUIDE中構建「視頻播放器」時,Iv'e遇到了類似的問題,第一個建議爲我解決了這個問題。

0

因此,我與MathWorks支持人員就此問題進行了交流。不幸的是,這似乎是R2016b和2017a中普遍存在的已知問題,可能會在未來版本中修復。支持無法爲我提供解決方法,所以目前我只是將測量數據打印到matlab命令行。