%%
clc;
global t;
global x;
global m;
global ii;
t = [0];
m = [0];
ii = 0;
x = -100;
p = plot(t,m,'EraseMode','background','MarkerSize',5);
axis([x-200 x+200 -90 90]);
grid on;
%%
try
s=serial('com4');
catch
error('cant serial');
end
set(s,'BaudRate', 115200,'DataBits',8,'StopBits',1,'Parity','none','FlowControl','none');
s.BytesAvailableFcnMode = 'terminator';
s.BytesAvailableFcn = {@callback,p};
fopen(s);
pause;
fclose(s);
delete(s);
clear s
close all;
clear all;
%%
function callback(s, BytesAvailable,p)
global t;
global x;
global m;
global ii;
out = fscanf(s);
data = str2num(out)
t = [t ii];
m = [m data];
set(p, 'XData',t,'YData',m(1,:));
drawnow
x = x + 1;
axis([x-200 x+200 -90 90]);
ii=ii+1;
end