Matlab updates figure too slowly

1 view (last 30 days)
Friedrich Krohn
Friedrich Krohn on 1 Oct 2020
Commented: Friedrich Krohn on 2 Oct 2020
I have a timer function set to a 0.02s Timer period that reads in voltage from an arduino via a serial port 's' and then sets the position of a rectangle according to the measured voltage using the handle 'bb' that I passed to the callback function. My problem is that Matlab updates the position of the rectangle with a roughly 5s delay and then stalls although each iteration takes less than 0.001s to execute. If I use the slower readVoltage command, then I do not have that problem. Is the 'set' command too slow to keep up with the 50 Hz?
The code is the following:
function disp_function (obj,~,bb,s)
n=get(obj,'TasksExecuted');
data=fscanf(s,'%f'); %get the voltage from
bar_pos = ((data - 0.7) ) *2 ;
bar_pos = round(bar_pos*100)/100;
% UpdatePlot(bar_pos);
set(bb,'Position', [0.2,bar_pos,0.6,0.1]) %bar handle
drawnow
% newdat=tmp_data;
end
  2 Comments
VBBV
VBBV on 2 Oct 2020
Edited: VBBV on 2 Oct 2020
Use
% if true
% code
% end
drawnow limitrate
To update figure faster
Friedrich Krohn
Friedrich Krohn on 2 Oct 2020
I tried that but I use Matlab 2016a and there, drawnow limitrate is not available

Sign in to comment.

Answers (0)

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!