[Scilab-users] How to replace Matlab stairs function in Scilab

Serge Steer Serge.Steer at inria.fr
Thu Sep 24 09:32:29 CEST 2015


Thers is no stair function but you can obtain this king of plot using
the polyline_properties:

clf;plot(sin(linspace(0,2*%pi,40)))
e=gce();//plot creates an entity of type compound
p=e.children;//the handle on the polyline
p.polyline_style=2; //set stair case mode

Serge Steer

Le 24/09/2015 05:11, Robert McLean MD PhD a écrit :
> So here is what I did for the stairs graph: 
>
> // we are going to make a stair step graphing program in scilab
> //              o------o
> //      o--o    |      |
> //         |    |      o---o
> //         o----o
> //
> // We take the vector (x1,x2,x3,...,xn) and (y1,y2,y3,...,yn) and instead of 
> // graphing a lines from the data points (x1,y1) to (x2,y2), (x2,y2) to
> (x3,y3),
> // etc., we graph (x1,y1) to (x2,y1) then (x2,y1) to (x2,y2), etc. 
> //
> // the number of graphed points goes from n to 2n-1. 
>
> // (x1,x2,...,xn) 
> // (y1,y2,...,yn) goes to
> // (x1,x2,x2,x3,x3,x4,x4,...)
> // (y1,y1,y2,y2,y3,y3,y4,...)
>
> function stairs(x,y)
>     n=length(x);
>     x_indices=int((1:2*n-1)/2)+1; // gives 1,2,2,3,3,...,2n-1,2n-1
>     x_ss=x(x_indices);  // the stair step graph's x values
>     y_indices=int((2:2*n)/2);  // gives 1,1,2,2,...,2n-2,2n-2,2n-1
>     y_ss=y(y_indices)
>     plot2d(x_ss,y_ss)
> endfunction
>
> // We create an example: 
> n=10;
> x=linspace(0,2,n);
> x=x.*x;  //irregularly spaced x interval points from 0 to 4
> y=sin(x*%pi);
> stairs(x,y)
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/How-to-replace-Matlab-stairs-function-in-Scilab-tp2615846p4032896.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>




More information about the users mailing list