Increase App Designer UI Elements Update Frequency

I am currently trying to display the data that I receive through the serial port in a Matlab application developer application. I suffer from the terrifying refresh rate of linear sensors (~ 1 Hz).

The values โ€‹โ€‹of the sensors are updated by a timer with a fixed speed, which is set to 30 Hz. Printing a timestamp in a timer callback shows me that it is being called at the correct frequency. My computer is quite soft, and the task manager does not show any hints of high load. In fact, MATLAB uses virtually no CPU time. In fact, these are not only pressure gauges, but also all elements of the user interface.

So, my guess is - or better: my hope is that there should be some kind of hard cap on the refresh rate. The official documentation does not give any guidance on how to change this.

My version of MATLAB is R2016b.

So my question (s):

  • Is it fixed with R2017a?

  • If not: can I do something with this, that is, using the built-in MATLAB files?

Here is an MCV example demonstrating the problem:

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 

Change I noticed that the sensor updates immediately when I turn the knob, slider, etc. So perhaps there is the possibility of a higher refresh rate ... but how to enable it without having to touch the controls? Updated MCV accordingly.

+6
source share
4 answers

You should be able to force the update by calling the drawnow function in the refreshMeter .

+2
source

I would suggest the following steps to help solve your problem:

  • follow this very useful link that provides mathworks solution for low graphics issues. This may be relevant to your graphics card.

  • The following suggestion by @MrAzzamans, drawnow and refreshdata may help solve your problem (keep in mind that they have different calling options).

  • If you are using GUIDE, try switching to App Designer and see if it solves your problem.

Iv'e encountered similar problems when creating a "video player" in GUIDE, the first sentence fixed it for me.

+2
source

So, I contacted MathWorks support regarding this issue. Unfortunately, this is apparently a known issue, common both in R2016b and in 2017, which could be fixed in future releases. Support also cannot provide me with a workaround, so for now I just print the measurement data on the matlab command line.

0
source

I found a way to get events to trigger an update for the widget for which the widow was inoperate: try sendkeys with carriage return:

h = actxserver ('WScript.shell'); h.SendKeys (line feed);

0
source

Source: https://habr.com/ru/post/1269581/


All Articles