 <p>There's an awful lot more happening in your loop than needs to be - it is considerably quicker to plot once then update the data, rather than tearing down the plot and creating a new one every time.</p> <p>Here's an idea for a more efficient arrangement (composed in browser, may contain errors):</p> <pre><code>clear; yThresh = 2.5; delete(instrfindall); s = serial('COM7', 'BaudRate', 57600); fopen(s); arq = fopen('dados.txt', 'w'); a = NaN(1,20); x = -18:1; subplot(3,1,1); hline = plot(x, a); haxes = gca; title('AcelX','fontsize',13,'fontweight','bold'); xlabel('Tempo','fontsize',10,'fontweight','bold'); ylabel('AcelX','fontsize',10,'fontweight','bold'); axis([1 3 -yThresh yThresh]); while ~feof(arq) %end of file newdata = fscanf(s, '%f%f%f'); a = [a(2:end) newdata(1)]; x = x + 1; % presumably you want to capture the data to that file at some point too? set(hline, 'XData', x, 'YData', a); xlim(haxes, [max(1,x(1)) x(end)]); end </code></pre> <p>For maximum update speed you might save a little more time by cheating the x axis - instead of changing the x data and axes limits each time, leave them untouched and just change the the tick labels (Or just forego the tick labels entirely, leaving nothing to update but the y data).</p>