clear all;
delete(instrfindall);
clear;
close all;
clc;
serialPort = 'COM3';
plotTitle = 'Sine Wave';
xLabel = 'Time (s)';
yLabel = 'Data';
plotGrid = 'on';
min = -1.5;
max = 1.5;
delay = .01;
time = 0;
data = 0;
count = 0;
plotGraph = plot(time,data,'-r');
title(plotTitle,'FontSize',18);
xlabel(xLabel,'FontSize',15);
ylabel(yLabel,'FontSize',15);
axis([0 10 min max]);
grid(plotGrid);
s= serial(serialPort);
disp('Close Plot to clear data');
fopen(s);
tic
while time <=50
dat = fscanf(s,'%f');
if(~isempty(dat) && isfloat(dat))
count = count + 1;
time(count) = toc;
data(count) = dat(1);
set(plotGraph,'XData',time,'YData',data);
axis([0 time(count) min max]);
end
pause(delay);
end
fclose(s);
clear count dat delay max min plotGraph plotGrid plotTitle s ...
serialPort xLabel yLabel;