Matlab updates figure too slowly

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 件のコメント

VBBV
VBBV 2020 年 10 月 2 日
編集済み: VBBV 2020 年 10 月 2 日
Use
% if true
% code
% end
drawnow limitrate
To update figure faster
Friedrich Krohn
Friedrich Krohn 2020 年 10 月 2 日
I tried that but I use Matlab 2016a and there, drawnow limitrate is not available

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

質問済み:

2020 年 10 月 1 日

コメント済み:

2020 年 10 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by