Matlab updates figure too slowly
Ältere Kommentare anzeigen
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 Kommentare
Use
% if true
% code
% end
drawnow limitrate
To update figure faster
Friedrich Krohn
am 2 Okt. 2020
Antworten (0)
Kategorien
Mehr zu Arduino Hardware finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!