<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065</link>
    <title>MATLAB Central Newsreader - Plotting a real time graph</title>
    <description>Feed for thread: Plotting a real time graph</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 28 Nov 2008 11:02:37 -0500</pubDate>
      <title>Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#613696</link>
      <author>arindam</author>
      <description>I am designing a device, which needs to communicate with MATLAB via serial port&lt;br&gt;
&lt;br&gt;
I need to have a CLI for taking values from the user which can be transmitted to the device. This has been done.&lt;br&gt;
&lt;br&gt;
I have now run into this problem...&lt;br&gt;
The device transmits a series of numbers which need to be plotted real time. Can this be done on MATLAB?&lt;br&gt;
The CLI also needs to be active and available at the same time. &lt;br&gt;
&lt;br&gt;
Could someone please point me in the right direction? Please feel free to offer any suggestions or ideas that you might have.&lt;br&gt;
&lt;br&gt;
I am new to MATLAB, but not to programming.</description>
    </item>
    <item>
      <pubDate>Fri, 28 Nov 2008 12:59:40 -0500</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#613711</link>
      <author>arindam</author>
      <description>I am not asking for a complete solution here ... I just a nudge in the right direction. You might mention any command or library, and i will dig into it.</description>
    </item>
    <item>
      <pubDate>Fri, 28 Nov 2008 13:23:02 -0500</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#613716</link>
      <author>Oliver Woodford</author>
      <description>In terms of plotting you will find the following functions useful: plot, hold, drawnow.&lt;br&gt;
&lt;br&gt;
For example:&lt;br&gt;
&amp;gt;&amp;gt; figure;&lt;br&gt;
&amp;gt;&amp;gt; hold on;&lt;br&gt;
&amp;gt;&amp;gt; for a = 1:1e3&lt;br&gt;
&amp;gt;&amp;gt; plot(rand(1), rand(1), 'r+');&lt;br&gt;
&amp;gt;&amp;gt; drawnow;&lt;br&gt;
&amp;gt;&amp;gt; end&lt;br&gt;
&lt;br&gt;
I don't know about serial data, but perhaps you could try setting up a callback function to call the relevant plotting functions.</description>
    </item>
    <item>
      <pubDate>Fri, 28 Nov 2008 13:48:02 -0500</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#613721</link>
      <author>Ryan Ollos</author>
      <description>arindam &amp;lt;goswamiarindam@gmail.com&amp;gt; wrote in message &amp;lt;12009090.1227870188030.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I am designing a device, which needs to communicate with MATLAB via serial port&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I need to have a CLI for taking values from the user which can be transmitted to the device. This has been done.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have now run into this problem...&lt;br&gt;
&amp;gt; The device transmits a series of numbers which need to be plotted real time. Can this be done on MATLAB?&lt;br&gt;
&amp;gt; The CLI also needs to be active and available at the same time. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Could someone please point me in the right direction? Please feel free to offer any suggestions or ideas that you might have.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am new to MATLAB, but not to programming.&lt;br&gt;
&lt;br&gt;
I'm not sure how you will get the data from the device to MATLAB, but one idea is to run a timer object that grabs data from the serial port object at the desired interval.  It appears that the serial port object has a TimerFcn, so you can probably put the code to display the data in that callback.&lt;br&gt;
&lt;br&gt;
As for plotting in real time, it sounds like you want a stripchart or the like.  There is a nice package here:  &lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/4722&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/4722&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Fri, 28 Nov 2008 14:43:17 -0500</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#613728</link>
      <author>arindam</author>
      <description>Thank you Oliver and Ryan,&lt;br&gt;
&lt;br&gt;
I now have an idea of how to proceed...&lt;br&gt;
I will implement time interval based callbacks which will&lt;br&gt;
&amp;nbsp;&amp;nbsp;1) read the input buffer of the serial object&lt;br&gt;
&amp;nbsp;&amp;nbsp;2) callback the stripchart function&lt;br&gt;
That should give me a real time plot with a rolling window&lt;br&gt;
:)&lt;br&gt;
If it works, I will share the results with you this Monday.&lt;br&gt;
Thanks again</description>
    </item>
    <item>
      <pubDate>Fri, 01 May 2009 14:02:01 -0400</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#646630</link>
      <author>Elettro Saldatura</author>
      <description>I am doing quite the same thing: trying to display data from an accelerometer with a serial interface.&lt;br&gt;
The serial interface is quite simple&lt;br&gt;
s=serial('comN');&lt;br&gt;
fopen(s);&lt;br&gt;
&lt;br&gt;
%then i send a command to the device&lt;br&gt;
char*;&lt;br&gt;
fprintf( s,'adc%c',char);&lt;br&gt;
&lt;br&gt;
%and then i get the values back&lt;br&gt;
string=fgetl(s);&lt;br&gt;
&lt;br&gt;
now the string has to be parsed (at least this is what i do: i convert char encoding to numbers), and you have your values.&lt;br&gt;
For me it's a Vector3.&lt;br&gt;
&lt;br&gt;
Now what i do to represent.&lt;br&gt;
I do some math with the data (filtering and normalizing) and implement a simple delay: (non working code)&lt;br&gt;
&lt;br&gt;
hline=plot&lt;br&gt;
while(ishandle(hline))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a=cputime;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while(b&amp;lt;(a+0.01))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;b=cputime;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;do whatever is necessary&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
in the plot you draw the first picture, then it is updated every time the &quot;for&quot; runs.&lt;br&gt;
a+0.01 is the delay&lt;br&gt;
&lt;br&gt;
Hope this helps.</description>
    </item>
    <item>
      <pubDate>Fri, 01 May 2009 14:14:02 -0400</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#646634</link>
      <author>Elettro Saldatura</author>
      <description>&quot;Elettro Saldatura&quot; &amp;lt;erupter_remove_this_@tiscali.it&amp;gt; wrote in message &lt;br&gt;
&amp;gt; in the plot you draw the first picture, then it is updated every time the &quot;for&quot; runs.&lt;br&gt;
&amp;gt; a+0.01 is the delay&lt;br&gt;
&lt;br&gt;
My error.&lt;br&gt;
I meant the &quot;while&quot;.&lt;br&gt;
The program automatically quits when the graph window is closed.</description>
    </item>
    <item>
      <pubDate>Fri, 10 Jul 2009 12:54:01 -0400</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#664236</link>
      <author>Cristian Zivieri</author>
      <description>arindam &amp;lt;goswamiarindam@gmail.com&amp;gt; wrote in message &amp;lt;23963555.1227883427711.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Thank you Oliver and Ryan,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I now have an idea of how to proceed...&lt;br&gt;
&amp;gt; I will implement time interval based callbacks which will&lt;br&gt;
&amp;gt;   1) read the input buffer of the serial object&lt;br&gt;
&amp;gt;   2) callback the stripchart function&lt;br&gt;
&amp;gt; That should give me a real time plot with a rolling window&lt;br&gt;
&amp;gt; :)&lt;br&gt;
&amp;gt; If it works, I will share the results with you this Monday.&lt;br&gt;
&amp;gt; Thanks again&lt;br&gt;
&lt;br&gt;
Hello to everybody,&lt;br&gt;
&lt;br&gt;
I've done the same thing as you: I receive data from a serial port (by USB converter) on my notebook and I plot them &quot;real-time&quot; with stripchart (it works good). My problem is that I receive data every 5 ms, so Matlab is not able to follow this tempistic and I observe a &quot;real time&quot; graphic with a big delay. In particular, each fscanf to read data needs about 20 ms. &lt;br&gt;
The question is the follow: is there an instruction similar to fscanf but faster?&lt;br&gt;
&lt;br&gt;
Thanks&lt;br&gt;
&lt;br&gt;
Cristian Zivieri</description>
    </item>
    <item>
      <pubDate>Fri, 10 Jul 2009 12:54:01 -0400</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#664237</link>
      <author>Cristian Zivieri</author>
      <description>arindam &amp;lt;goswamiarindam@gmail.com&amp;gt; wrote in message &amp;lt;23963555.1227883427711.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Thank you Oliver and Ryan,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I now have an idea of how to proceed...&lt;br&gt;
&amp;gt; I will implement time interval based callbacks which will&lt;br&gt;
&amp;gt;   1) read the input buffer of the serial object&lt;br&gt;
&amp;gt;   2) callback the stripchart function&lt;br&gt;
&amp;gt; That should give me a real time plot with a rolling window&lt;br&gt;
&amp;gt; :)&lt;br&gt;
&amp;gt; If it works, I will share the results with you this Monday.&lt;br&gt;
&amp;gt; Thanks again&lt;br&gt;
&lt;br&gt;
Hello to everybody,&lt;br&gt;
&lt;br&gt;
I've done the same thing as you: I receive data from a serial port (by USB converter) on my notebook and I plot them &quot;real-time&quot; with stripchart (it works good). My problem is that I receive data every 5 ms, so Matlab is not able to follow this tempistic and I observe a &quot;real time&quot; graphic with a big delay. In particular, each fscanf to read data needs about 20 ms. &lt;br&gt;
The question is the follow: is there an instruction similar to fscanf but faster?&lt;br&gt;
&lt;br&gt;
Thanks&lt;br&gt;
&lt;br&gt;
Cristian Zivieri</description>
    </item>
    <item>
      <pubDate>Fri, 10 Jul 2009 12:54:02 -0400</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#664238</link>
      <author>Cristian Zivieri</author>
      <description>arindam &amp;lt;goswamiarindam@gmail.com&amp;gt; wrote in message &amp;lt;23963555.1227883427711.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Thank you Oliver and Ryan,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I now have an idea of how to proceed...&lt;br&gt;
&amp;gt; I will implement time interval based callbacks which will&lt;br&gt;
&amp;gt;   1) read the input buffer of the serial object&lt;br&gt;
&amp;gt;   2) callback the stripchart function&lt;br&gt;
&amp;gt; That should give me a real time plot with a rolling window&lt;br&gt;
&amp;gt; :)&lt;br&gt;
&amp;gt; If it works, I will share the results with you this Monday.&lt;br&gt;
&amp;gt; Thanks again</description>
    </item>
    <item>
      <pubDate>Mon, 15 Feb 2010 15:20:05 -0500</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#717741</link>
      <author>sagarika g</author>
      <description>im  working in a similar way.im taking finger movement and catching those movements through accelerometer with a built in ADC in it and sending those sampled values into pc through RS232.how to record those sampled values while coming out of serial port and how to plot them. can u help me in the matlab code.......&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Elettro Saldatura&quot; &amp;lt;erupter_remove_this_@tiscali.it&amp;gt; wrote in message &amp;lt;gtevcp$b0s$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I am doing quite the same thing: trying to display data from an accelerometer with a serial interface.&lt;br&gt;
&amp;gt; The serial interface is quite simple&lt;br&gt;
&amp;gt; s=serial('comN');&lt;br&gt;
&amp;gt; fopen(s);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %then i send a command to the device&lt;br&gt;
&amp;gt; char*;&lt;br&gt;
&amp;gt; fprintf( s,'adc%c',char);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %and then i get the values back&lt;br&gt;
&amp;gt; string=fgetl(s);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; now the string has to be parsed (at least this is what i do: i convert char encoding to numbers), and you have your values.&lt;br&gt;
&amp;gt; For me it's a Vector3.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Now what i do to represent.&lt;br&gt;
&amp;gt; I do some math with the data (filtering and normalizing) and implement a simple delay: (non working code)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; hline=plot&lt;br&gt;
&amp;gt; while(ishandle(hline))&lt;br&gt;
&amp;gt;     a=cputime;&lt;br&gt;
&amp;gt;     while(b&amp;lt;(a+0.01))&lt;br&gt;
&amp;gt;         b=cputime;&lt;br&gt;
&amp;gt;     end&lt;br&gt;
&amp;gt;     do whatever is necessary&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; in the plot you draw the first picture, then it is updated every time the &quot;for&quot; runs.&lt;br&gt;
&amp;gt; a+0.01 is the delay&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hope this helps.</description>
    </item>
    <item>
      <pubDate>Mon, 15 Feb 2010 16:45:04 -0500</pubDate>
      <title>Re: Plotting a real time graph</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240065#717768</link>
      <author>John </author>
      <description>&amp;gt; im  working in a similar way.im taking finger movement and catching those movements through accelerometer with a built in ADC in it and sending those sampled values into pc through RS232.how to record those sampled values while coming out of serial port and how to plot them. can u help me in the matlab code.......&lt;br&gt;
&lt;br&gt;
I've done quite a bit of experimenting with a real-time GUI with an output graph and retrieving RS232 data to plot.&lt;br&gt;
&lt;br&gt;
My solution was to use a number of timers set up in repeating, queued mode... these are the relevant ones:&lt;br&gt;
1.  Read serial data timer&lt;br&gt;
Every X ms (I'm using 120ms), read all data in from the serial port and stuff it in a buffer.  Then, parse the serial data buffer looking for data packets then place the data in the appropriate incoming data buffer - I have a number of separate data streams coming in that I graph separately, so each data stream has its own buffer.&lt;br&gt;
3.  Update graph timer&lt;br&gt;
This checks if any of the graph data buffers was updated and, if so, it updates the graph.&lt;br&gt;
&lt;br&gt;
There are a couple ways I found to keep things rolling smoothly:&lt;br&gt;
1.  Make sure the read serial timer doesn't take up all the processor: slow it down and increase the UART buffer if necessary to prevent overflows in between reads.&lt;br&gt;
2.  Don't try to update the graph too quickly; I have a drop box on my GUI to control the rate, so if it's having issues I slow it down.&lt;br&gt;
3.  Use the &quot;drawnow&quot; function to make sure the graph gets updated each time through.  This will slow down the UART read timer if it takes too long.&lt;br&gt;
4.  Update the graph by setting the data line with the new data, not by calling &quot;plot&quot; each time; then, change the X-axis to the new max dimension.  I.E.:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set(plotHandle,'XData',Xindex,'YData',data.X);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;axis( handles.dat1Graph, [1 size(data.X,1) -100 100 ] );&lt;br&gt;
5.  The graph will update more quickly if you set the X-axis to be as long as you expect the data to be; then it won't have to rescale the axis each time through.&lt;br&gt;
&lt;br&gt;
I hope that helps; I tried the stripchart but it didn't do what I wanted, as I wanted to be able to watch the incoming data build up, have smoothed lines, and be able to zoom in and out.</description>
    </item>
  </channel>
</rss>

