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:
can matlab plot a dynamic graph??

Subject: can matlab plot a dynamic graph??

From: 05358842d

Date: 12 Apr, 2008 09:07:17

Message: 1 of 11

Dear all,

I wanna plot a graph with dynamic motion to show the line from the first point to the last point. Is it possible??
If yes, please show me the code! Urgent! Thank you very much! I am so desperate to have it a.s.a.p!

Thank you,
john

Subject: can matlab plot a dynamic graph??

From: avan

Date: 12 Apr, 2008 10:40:25

Message: 2 of 11

On Apr 12, 11:07 am, 05358842d <053588...@polyu.edu.hk> wrote:
> Dear all,
>
> I wanna plot a graph with dynamic motion to show the line from the first point to the last point. Is it possible??
> If yes, please show me the code! Urgent! Thank you very much! I am so desperate to have it a.s.a.p!
>
> Thank you,
> john

Maybe this can help you:

%% CODE
figure;

% line function
f = @(x) x.^2;

% x intervals
xi = -5:0.1:5;

% plot
plot(xi,f(xi));

% motions
hold on;
for i=1:length(xi)
    h = plot(xi(i),f(xi(i)),'ro','MarkerFaceColor','r');
    pause(0.01);
    delete(h);
end

% END OF CODE


avan

Subject: can matlab plot a dynamic graph??

From: 05358842d

Date: 12 Apr, 2008 11:14:13

Message: 3 of 11

Dear Avan,

Thank you for your reply!

The animation generated from your code is really what i needed. However, there were many red pts were shown instead of a red pt running thru the path after I modified your kindly provided code.

%% CODE
figure;
% line function
%f = @(x) x.^2;
% x intervals
xi = -5:0.1:5;
% plot
plot3(b(1,:),b(2,:),b(3,:));
% motions
hold on;
for i=1:length(xi)
h = plot3(b(1,:),b(2,:),b(3,:),'ro','MarkerFaceColor','r');
pause(0.01);
delete(h);
end

As I am a beginner in matlab, please point out what i was wrong.

Thank you,
john

Subject: can matlab plot a dynamic graph??

From: avan

Date: 12 Apr, 2008 16:13:05

Message: 4 of 11

On Apr 12, 1:14=A0pm, 05358842d <053588...@polyu.edu.hk> wrote:
> Dear Avan,
>
> Thank you for your reply!
>
> The animation generated from your code is really what i needed. However, t=
here were many red pts were shown instead of a red pt running thru the path =
after I modified your kindly provided code.
>
> %% CODE
> figure;
> % line function
> %f =3D @(x) x.^2;
> % x intervals
> xi =3D -5:0.1:5;
> % plot
> plot3(b(1,:),b(2,:),b(3,:));
> % motions
> hold on;
> for i=3D1:length(xi)
> h =3D plot3(b(1,:),b(2,:),b(3,:),'ro','MarkerFaceColor','r');
> pause(0.01);
> delete(h);
> end
>
> As I am a beginner in matlab, please point out what i was wrong.
>
> Thank you,
> john

John, I tried your code but it doesn't work. The matrix b is
undefined. I couldn't figure it out what it means.



Avan

Subject: can matlab plot a dynamic graph??

From: matt dash

Date: 13 Apr, 2008 03:32:01

Message: 5 of 11

someone had this exact same problem two weeks ago...

try changing your :'s to i's in this line:
h = plot3(b(1,:),b(2,:),b(3,:),'ro','MarkerFaceColor','r');

if that still isn't what you want, change the :'s to (1:i)'s
(without the parentheses)

and delete the hold on and delete(h) lines if you want the
dot to stay in its final position at the end of the animation.

Subject: can matlab plot a dynamic graph??

From: colin

Date: 14 Apr, 2008 12:04:33

Message: 6 of 11

Howzit,

What about

plot(...)
hold('on')
comet(...)

Shouldn't that work?

Colin

Subject: can matlab plot a dynamic graph??

From: Paul Mennen

Date: 14 Apr, 2008 23:07:14

Message: 7 of 11

> I wanna plot a graph with dynamic motion to show the line
> from the first point to the last point. Is it possible??
> john

Yes it is certainly possible. I have a bunch of example
programs which show plots in dynamic motion. You can
get them by downloading "plt" from the file exchange.
(Look in the demo folder). These demo programs call plt
instead of plot but the principles of getting moving
graphs are the same.

The program called "dice.m" is the most similar to what
it sounds like you are trying to do. It plots one or
two functions as they are being computed (i.e. as the
length of the function continues to grow.) You can start
it, stop it, single step, and control its speed from the
uicontrols. Other examples in the demo folder that involve
moving traces that you may want to look at are: bounce.m,
pltsq.m, and wfall.m

~Paul

Subject: can matlab plot a dynamic graph??

From: Paul Mennen

Date: 14 Apr, 2008 23:07:14

Message: 8 of 11

> I wanna plot a graph with dynamic motion to show the line
> from the first point to the last point. Is it possible??
> john

Yes it is certainly possible. I have a bunch of example
programs which show plots in dynamic motion. You can
get them by downloading "plt" from the file exchange.
(Look in the demo folder). These demo programs call plt
instead of plot but the principles of getting moving
graphs are the same.

The program called "dice.m" is the most similar to what
it sounds like you are trying to do. It plots one or
two functions as they are being computed (i.e. as the
length of the function continues to grow.) You can start
it, stop it, single step, and control its speed from the
uicontrols. Other examples in the demo folder that involve
moving traces that you may want to look at are: bounce.m,
pltsq.m, and wfall.m

~Paul

Subject: can matlab plot a dynamic graph??

From: Paul Mennen

Date: 14 Apr, 2008 23:07:27

Message: 9 of 11

> I wanna plot a graph with dynamic motion to show the line
> from the first point to the last point. Is it possible??
> john

Yes it is certainly possible. I have a bunch of example
programs which show plots in dynamic motion. You can
get them by downloading "plt" from the file exchange.
(Look in the demo folder). These demo programs call plt
instead of plot but the principles of getting moving
graphs are the same.

The program called "dice.m" is the most similar to what
it sounds like you are trying to do. It plots one or
two functions as they are being computed (i.e. as the
length of the function continues to grow.) You can start
it, stop it, single step, and control its speed from the
uicontrols. Other examples in the demo folder that involve
moving traces that you may want to look at are: bounce.m,
pltsq.m, and wfall.m

~Paul

Subject: can matlab plot a dynamic graph??

From: Paul Mennen

Date: 14 Apr, 2008 23:07:27

Message: 10 of 11

> I wanna plot a graph with dynamic motion to show the line
> from the first point to the last point. Is it possible??
> john

Yes it is certainly possible. I have a bunch of example
programs which show plots in dynamic motion. You can
get them by downloading "plt" from the file exchange.
(Look in the demo folder). These demo programs call plt
instead of plot but the principles of getting moving
graphs are the same.

The program called "dice.m" is the most similar to what
it sounds like you are trying to do. It plots one or
two functions as they are being computed (i.e. as the
length of the function continues to grow.) You can start
it, stop it, single step, and control its speed from the
uicontrols. Other examples in the demo folder that involve
moving traces that you may want to look at are: bounce.m,
pltsq.m, and wfall.m

~Paul

Subject: can matlab plot a dynamic graph??

From: Paul Mennen

Date: 14 Apr, 2008 23:14:02

Message: 11 of 11

I didn't post my response 4 times on purpose.
My browser hung after I hit "Post Message" and it seemed
to do that all by itself. Sorry about that.
~Paul

> Yes it is certainly possible. ...
> ~Paul

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