Question: How do I use a relational operator to do inplace substitution into a list?

I have a list of values in the range from 1 to 6 inclusive:

    [> y := [ seq(rand(1..6)(), i = 1..10) ] : # step 1

I would like to replace all elements <= 3 with -1 and all elements > 3 with 1

    [> y := subs(1=-1, 2=-1, 3=-1, 4=1, 5=1, 6=1, y) : # step 2

Then calculate the cumulative sum

    [> y := [ seq(add(y[ .. i]), i = 1..n) ] : # step 3

And plot the results

    [> plot([ seq(i, i = 1..n) ], y) # step 4
 

This all works, but step 2 is downright ugly. Is there a more elegant expression available?

And step 4 requires I generate an extra data set for the x-axis. Is there a way to specify just the the y-values and have Maple assume the x-values are in the range  1..nops(y)? (Something akin to just  plot(y), which produces output I don't understand.)

By way of example, I am trying to replicate this MATLAB expression:

    > y = cumsum(2*(randi(6, 10, 1) <= 3) - 1); plot(y)

 

 

Please Wait...