i am simply printing there floats form my arduino or any other serial output device... in matlab i am receiving them and plotting them. it is being printed in arduino very fast but in matlab it is slower and after a a minute or so the plot is not reacting to the numbers from arduino fast... it seams matlab is slower and it is keeping the records in buffer? how can i clear it and get the fresh data plotted?
one more thing does it make sense that matlab can't import and plot a few numbers in 100Hz? What i am doing wrong or inefficient ?
clc
clear all
h = figure(1);
set(h,'UserData',1);
s=serial('/dev/tty.usbmodem1411','BaudRate',115200);
set(s,'DataBits',8);
set(s,'StopBits',1);
fopen(s);
s.ReadAsyncMode='continuous';
readasync(s);
tStart = tic;
xplot=subplot(3,1,1);
hold on;
xlabel('time(ms)');
ylabel('X angle(deg)');
yplot=subplot(3,1,2);
hold on;
xlabel('time(ms)');
ylabel('Y angle(deg)');
zplot=subplot(3,1,3);
hold on;
xlabel('time(ms)');
ylabel('Z angle(deg)');
cont=true;
xAngle = zeros(1,1000000);
yAngle = zeros(1,1000000);
zAngle = zeros(1,1000000);
i=0;
while(true)
i=i+1;
t = toc(tStart);
%angle = fscanf(s, '%f');
[x y z] = strread(fgetl(s,s.BytesAvailable),'%f %f %f');
plot(xplot,t,x,'.');
plot(yplot,t,y,'.');
plot(zplot,t,z,'.');
drawnow;
end fclose(s);