Subscribe Bookmark RSS Feed

Wait function within a for loop within graph box..

sam_cartwright1

Community Trekker

Joined:

Aug 5, 2015

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
Solution

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
Solution

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;

);

sam_cartwright1

Community Trekker

Joined:

Aug 5, 2015

Brilliant! Exactly what I wanted to achieve

ian_jmp

Staff

Joined:

Jun 23, 2011

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.

sam_cartwright1

Community Trekker

Joined:

Aug 5, 2015

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

ian_jmp

Staff

Joined:

Jun 23, 2011

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

11213_Screen Shot 2016-03-29 at 16.40.59.png



ms

Super User

Joined:

Jun 23, 2011

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.


Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

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

The Data Filter also has an animation feature.

-Jeff

-Jeff
sam_cartwright1

Community Trekker

Joined:

Aug 5, 2015

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