On 13/03/2013 13:01, Adrien Vogt-Schilb wrote:

Samuel once provided a solution to this:
For the record: actually it was Antoine, and he provided a function.

Could still be deposited to fileexchange. Antoine would you allow your function to be posted? Do you happen to have a more recent version than the one you posted back in 2011:



Here is an example:

x=[-10:10];y1=x+10;y2=x.*x;
BetweenCurves(x,y1,y2);


Here is the source code below:


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Plot area between two curves
function [h,epoly,ey1,ey2]=BetweenCurves(x,y1,y2,varargin)
//
//      Plots two curves and fill the area in between
//
//      INPUTS:
//              x       vector (1,n) of horizontal coordinates
//              y1      vector (1,n) value of 1st curve y1(x)
//              y2      vector (1,n) value of 2nd curve y2(x)
//       -- optional inputs: pairs "keyword","value" --
//              "handle",h      handle to the graphic window to use
//              "axis",a      handle to the graphic axis to use
//              "foreground", colorid   id of the color to use for
painting the area
//              "background", colorid   id of the color to use for
curves stroke
//
//      OUTPUTS:
//              h       handle to the graphic window used
// epoly handle to the polygone that fill the area in between
//              ey1     handle to first curve
//              ey2     handle to second curve

//default values for optional argument
       hfig=-1;
       background=%nan;
       foreground=%nan;
// scan varargin for optional parameter pairs (they can appear in any order)
    for i=1:2:length(varargin)
       keyword=varargin(i);
       value=varargin(i+1);
       select keyword
          case "handle" then
             hfig=value;
             scf(hfig);
          case "axis" then
             axis=value;
             sca(axis);
             hfig=axis.parent;
          case "background" then
             background=value;
          case "foreground" then
             background=value;
       end
    end
// special treatment for handle (aka hack alert)
    if typeof(hfig) ~= "handle" then
       hfig=scf();
    end
    h=hfig;
    scf(hfig);
    xfpoly([x,x($:-1:1)],[y1,y2($:-1:1)]);
    epoly=gce();
    plot(x,y1);
    ey1=gce();
    plot(x,y2);
    ey2=gce();
// background setting
    if (~isnan(background)) then
       // optional background specified
       epoly.background=background;
    else
       // default background
       epoly.background=color("gray87");
    end
// foreground setting (as for background)
    if (~isnan(foreground)) then
       epoly.foreground=foreground;
       ey1.children.foreground=foreground;
       ey2.children.foreground=foreground;
    else
       epoly.foreground=color("gray65");
       ey1.children.foreground=color("gray65");
       ey2.children.foreground=color("gray65");
    end
endfunction
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

--
Adrien Vogt-Schilb (Cired)
Tel: (+33) 1 43 94 73 83

_______________________________________________
users mailing list
[email protected]
http://lists.scilab.org/mailman/listinfo/users

Reply via email to