|
i need to plot data from the serial port coming at regular
intervals, need to plot it in real time though, have tried
out a code but it only plots the graph at the end... can
someone help me out? i want the new data to be added to the
previous plot after each increment of the for loop
clc
clear all
close all
s1 = serial('COM1');
%define serial port
s1.BaudRate=9600;
%define baud rate
s1.ReadAsyncMode = 'continuous';
timeout=6;
fopen(s1);
%open serial port
clear data;
data(1)=fread(s1,1);
disp(sprintf('Temperature = %3.2f Degree C' ,data(1)/2))
plot(data)
title('Temperature Sensor')
xlabel('number of points')
ylabel('Temperature Degree C')
axis([0 40 0 128])
hold on;
for i= 2 :40
%acquisition of 100 points
data(i)=fread(s1,1);
%read sensor hex data
disp(sprintf('Temperature = %3.2f Degree C' ,data(i)/2))
plot(data);
%plot 100 points
end
fclose(s1);
%close serial port
|