Choose Language Hide Translation Bar

Community Trekker

Joined:

Aug 5, 2015

Wait function within a for loop within graph box..

Hi all,

I wanted to create a graph box that plots a point every, say, 0.5 seconds. The idea is that I can watch the evolution of my data through time for example.

Here is a simple script that doesn't work but it is how I imagined it working. Can somebody point to how you might achieve this?

x = [1 2 3 4 5];

y = -x;

New Window("Data evolution",

graph box(

for(i, i < 6, i++,

Marker(x[i], y[i]);

wait(0.5);

),

),

);

1 ACCEPTED SOLUTION

Accepted Solutions

Super User

Joined:

Jun 23, 2011

Solution

Re: Wait function within a for loop within graph box..

There are several ways to do this. Here's one example:

x = [1 2 3 4 5];

y = -x;

//Start values (as matrices)

xi = x[1 :: 1];

yi = y[1 :: 1];

nw = New Window("Data evolution", gb = Graph Box(X Scale(0, 6), Y Scale(-6, 0), Marker(xi, yi)));

For(i = 2, i < 6, i++,

Wait(0.5);

xi = x[1 :: i];

yi = y[1 :: i];

gb << reshow;

);

8 REPLIES 8

Super User

Joined:

Jun 23, 2011

Solution

Re: Wait function within a for loop within graph box..

There are several ways to do this. Here's one example:

x = [1 2 3 4 5];

y = -x;

//Start values (as matrices)

xi = x[1 :: 1];

yi = y[1 :: 1];

nw = New Window("Data evolution", gb = Graph Box(X Scale(0, 6), Y Scale(-6, 0), Marker(xi, yi)));

For(i = 2, i < 6, i++,

Wait(0.5);

xi = x[1 :: i];

yi = y[1 :: i];

gb << reshow;

);

Community Trekker

Joined:

Aug 5, 2015

Re: Wait function within a for loop within graph box..

Brilliant! Exactly what I wanted to achieve

Staff

Joined:

Jun 23, 2011

Re: Wait function within a for loop within graph box..

And (to prove the point) here's an alternative to the one provided by Marcus above:

x = [1 2 3 4 5];

y = x;

New Window( "Data evolution",

gb = Graph Box(X Scale( 0, 6 ), Y Scale( 0, 6 ), )

);

For( i = 1, i < 6, i++,

gb << Set Graphics Script (Marker(x[1::i], y[1::i]));

Wait( 0.5 );

);

I note that there were a couple of syntax errors in your sample code, so please be aware of 'Help > Scripting Index' and the examples therein.

Community Trekker

Joined:

Aug 5, 2015

Re: Wait function within a for loop within graph box..

Hi Ian,

I try to use the scripting index as much as possible but the matrix syntax is still a bit of a struggle for me at the moment.

For example I find that that

Marker(x, y) works

Marker(x[1::3], y[1::3]) works

Marker(x[1], y[1]) does not work

If you don't mind, what would be the correct syntax for a single point?

kind regards, Sam

Staff

Joined:

Jun 23, 2011

Re: Wait function within a for loop within graph box..

Don't worry - You will soon get it! If you want a single point, try Marker({x[1], y[1]}).

Super User

Joined:

Jun 23, 2011

Re: Wait function within a for loop within graph box..

Marker( ) requires matrix or list arguments.  x[1] returns a number by default, whereas x[1::2] returns a matrix. The odd syntax x[1::1] is a way to force the index to return a matrix for a single-number subscript.

Community Manager

Joined:

Jun 23, 2011

Re: Wait function within a for loop within graph box..

You could also use the Bubble Plot to get your data to animate.

The Data Filter also has an animation feature.

-Jeff

-Jeff

Community Trekker

Joined:

Aug 5, 2015

Re: Wait function within a for loop within graph box..

Ah ok, this makes sense now. Thanks for the responses.