Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to append to plot, or continuously update plot? plot3d? plot3?

Subject: How to append to plot, or continuously update plot? plot3d? plot3?

From: Kamil

Date: 30 Jul, 2009 16:23:21

Message: 1 of 9

Hey,

I am trying to use matlab for "real time" processing and display.

I would like to update a plot with new data and have that data be
appended to a plot.

This will be a 3d plot using plot3 command. A constant X axis will be
defined for this figure and I would like to plot until the X axis is
completely filled up. 8 lines will be drawn on this plot.

This was my plan...
1) initialize the plot with some initial data. Also set the X axis to
the maximum length desired.
2) Update the plot
     2.1) get current data on plot using get(h, 'Xdata')
     2.2) make a new variable the length of oldXdata and newXdata.
     2.3) concat oldXdata with newXdata
     2.4) redraw

is there a simpler way to do this? I am getting lost because the
Xdata for a plot3d is a cell array and im having trouble combining the
newXdata with the oldXdata.

Any help would be appreciated,

Thanks,
Kamil

Subject: How to append to plot, or continuously update plot? plot3d? plot3?

From: Dave Brackett

Date: 31 Jul, 2009 15:25:05

Message: 2 of 9

Kamil <kamilczauz@gmail.com> wrote in message <b7dc6f03-1029-44d8-b812-352e3093302d@j19g2000vbp.googlegroups.com>...
> Hey,
>
> I am trying to use matlab for "real time" processing and display.
>
> I would like to update a plot with new data and have that data be
> appended to a plot.
>
> This will be a 3d plot using plot3 command. A constant X axis will be
> defined for this figure and I would like to plot until the X axis is
> completely filled up. 8 lines will be drawn on this plot.
>
> This was my plan...
> 1) initialize the plot with some initial data. Also set the X axis to
> the maximum length desired.
> 2) Update the plot
> 2.1) get current data on plot using get(h, 'Xdata')
> 2.2) make a new variable the length of oldXdata and newXdata.
> 2.3) concat oldXdata with newXdata
> 2.4) redraw
>
> is there a simpler way to do this? I am getting lost because the
> Xdata for a plot3d is a cell array and im having trouble combining the
> newXdata with the oldXdata.
>
> Any help would be appreciated,
>
> Thanks,
> Kamil


Have you tried plotting in a loop and using the 'hold on' command?

Subject: How to append to plot, or continuously update plot? plot3d? plot3?

From: dances_with_wolves N G

Date: 2 Aug, 2009 06:52:03

Message: 3 of 9

"Dave Brackett" <davebrackett@hotmail.com> wrote in message <h4v2ch$bs6$1@fred.mathworks.com>...
> Kamil <kamilczauz@gmail.com> wrote in message <b7dc6f03-1029-44d8-b812-352e3093302d@j19g2000vbp.googlegroups.com>...
> > Hey,
> >
> > I am trying to use matlab for "real time" processing and display.
> >
> > I would like to update a plot with new data and have that data be
> > appended to a plot.
> >
> > This will be a 3d plot using plot3 command. A constant X axis will be
> > defined for this figure and I would like to plot until the X axis is
> > completely filled up. 8 lines will be drawn on this plot.
> >
> > This was my plan...
> > 1) initialize the plot with some initial data. Also set the X axis to
> > the maximum length desired.
> > 2) Update the plot
> > 2.1) get current data on plot using get(h, 'Xdata')
> > 2.2) make a new variable the length of oldXdata and newXdata.
> > 2.3) concat oldXdata with newXdata
> > 2.4) redraw
> >
> > is there a simpler way to do this? I am getting lost because the
> > Xdata for a plot3d is a cell array and im having trouble combining the
> > newXdata with the oldXdata.
> >
> > Any help would be appreciated,
> >
> > Thanks,
> > Kamil
>
>
> Have you tried plotting in a loop and using the 'hold on' command?

hi Dave,
I tried using hold on, but the figure is not shown in real-time. It is AFTER all the plots are made.

Subject: How to append to plot, or continuously update plot? plot3d? plot3?

From: Bruno Luong

Date: 2 Aug, 2009 09:14:03

Message: 4 of 9


> is there a simpler way to do this? I am getting lost because the
> Xdata for a plot3d is a cell array and im having trouble combining the
> newXdata with the oldXdata.

Du you call GET with array of handle ? Fort single handle it returns double array.

Show important snips of your code.

You could also initialize your plots with NaN array having a maximum size, and fill progressively the tail NaN with real data. This might accelerate slightly the updating.

Bruno

Subject: How to append to plot, or continuously update plot? plot3d? plot3?

From: Bruno Luong

Date: 2 Aug, 2009 09:24:03

Message: 5 of 9

"dances_with_wolves N G" <karthickng@ieee.org> wrote in message <h53d2j$mgp$1@fred.mathworks.com>...

> hi Dave,
> I tried using hold on, but the figure is not shown in real-time. It is AFTER all the plots are made.

Use commands DRAWNOW or REFRESH to force the plot.

Bruno

Subject: How to append to plot, or continuously update plot? plot3d?

From: Richard

Date: 2 Aug, 2009 16:22:51

Message: 6 of 9

On Jul 31, 12:23 am, Kamil <kamilcz...@gmail.com> wrote:
> Hey,
>
> I am trying to use matlab for "real time" processing and display.
>
> I would like to update a plot with new data and have that data be
> appended to a plot.
>
> This will be a 3d plot using plot3 command.  A constant X axis will be
> defined for this figure and I would like to plot until the X axis is
> completely filled up.  8 lines will be drawn on this plot.
>
> This was my plan...
> 1) initialize the plot with some initial data.  Also set the X axis to
> the maximum length desired.
> 2) Update the plot
>      2.1) get current data on plot using get(h, 'Xdata')
>      2.2) make a new variable the length of oldXdata and newXdata.
>      2.3) concat oldXdata with newXdata
>      2.4) redraw
>
> is there a simpler way to do this?  I am getting lost because the
> Xdata for a plot3d is a cell array and im having trouble combining the
> newXdata with the oldXdata.
>
> Any help would be appreciated,
>
> Thanks,
> Kamil

Try
>>comet(xdata,ydata,zdata )
with loop. For 2D data, "comet" plots in real time. For 3D data, no
idea!

Cheers!
Richard

Subject: How to append to plot, or continuously update plot? plot3d?

From: Naveen Cherala

Date: 8 Apr, 2010 13:00:22

Message: 7 of 9

try pause in while(1) loop
E.g.
while(1)
.
.
update data
plot(x,data)
pause(time)
.
.
end


Richard <cqxu456@hotmail.com> wrote in message <a57dbf86-623a-4fea-8f9a-3c746a8655a5@f18g2000prf.googlegroups.com>...
> On Jul 31, 12:23 am, Kamil <kamilcz...@gmail.com> wrote:
> > Hey,
> >
> > I am trying to use matlab for "real time" processing and display.
> >
> > I would like to update a plot with new data and have that data be
> > appended to a plot.
> >
> > This will be a 3d plot using plot3 command.  A constant X axis will be
> > defined for this figure and I would like to plot until the X axis is
> > completely filled up.  8 lines will be drawn on this plot.
> >
> > This was my plan...
> > 1) initialize the plot with some initial data.  Also set the X axis to
> > the maximum length desired.
> > 2) Update the plot
> >      2.1) get current data on plot using get(h, 'Xdata')
> >      2.2) make a new variable the length of oldXdata and newXdata.
> >      2.3) concat oldXdata with newXdata
> >      2.4) redraw
> >
> > is there a simpler way to do this?  I am getting lost because the
> > Xdata for a plot3d is a cell array and im having trouble combining the
> > newXdata with the oldXdata.
> >
> > Any help would be appreciated,
> >
> > Thanks,
> > Kamil
>
> Try
> >>comet(xdata,ydata,zdata )
> with loop. For 2D data, "comet" plots in real time. For 3D data, no
> idea!
>
> Cheers!
> Richard

Subject: How to append to plot, or continuously update plot? plot3d? plot3?

From: Kristof Lieben

Date: 27 Dec, 2011 13:09:08

Message: 8 of 9

Kamil <kamilczauz@gmail.com> wrote in message <b7dc6f03-1029-44d8-b812-352e3093302d@j19g2000vbp.googlegroups.com>...
> Hey,
>
> I am trying to use matlab for "real time" processing and display.
>
> I would like to update a plot with new data and have that data be
> appended to a plot.
>
> This will be a 3d plot using plot3 command. A constant X axis will be
> defined for this figure and I would like to plot until the X axis is
> completely filled up. 8 lines will be drawn on this plot.
>
> This was my plan...
> 1) initialize the plot with some initial data. Also set the X axis to
> the maximum length desired.
> 2) Update the plot
> 2.1) get current data on plot using get(h, 'Xdata')
> 2.2) make a new variable the length of oldXdata and newXdata.
> 2.3) concat oldXdata with newXdata
> 2.4) redraw
>
> is there a simpler way to do this? I am getting lost because the
> Xdata for a plot3d is a cell array and im having trouble combining the
> newXdata with the oldXdata.
>
> Any help would be appreciated,
>
> Thanks,
> Kamil

Hello Kamil,

Can you tell us the solution?
How did you accomplish it?
I'd like to do the same but i'm missing some important steps apparenly.

Kind Regards,
Kristof

Subject: How to append to plot, or continuously update plot? plot3d? plot3?

From: xsystem1

Date: 17 Jul, 2012 11:16:18

Message: 9 of 9

[data,time] = s.startBackground;
plot(time,data)

Doesnt that update in realtime?

Tags for this Thread

No tags are associated with this thread.

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.

Contact us