Thread Subject: Real time plot

Subject: Real time plot

From: Ved Vernekar

Date: 5 May, 2008 16:19:03

Message: 1 of 2

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

Subject: Real time plot

From: Steven Lord

Date: 5 May, 2008 17:00:28

Message: 2 of 2


"Ved Vernekar" <vedvern@gmail.com> wrote in message
news:fvnc1n$ps8$1@fred.mathworks.com...
>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

Don't replot. Plot once before the loop (specifying an output, so you have
the handle to the plot) and update the XData and YData properties of that
handle inside the loop. You'll also want to use DRAWNOW after updating the
*Data properties, to make sure the graph redraws. Read through this section
of the documentation for more information and examples:

http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f10-1460.html

--
Steve Lord
slord@mathworks.com

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com