Example of section to separate data and join it back.
MGL code:
subplot 1 1 0 '<_':title 'Section&Join sample' axis:box:line -1 0 1 0 'h:' # first lets demonstrate 'join' new aa 11 'x^2':new a1 3 '-x':new a2 15 'x^3' join aa a1:join aa a2 # add x-coordinate new xx aa.nx 'x':join aa xx plot aa(:,1) aa(:,0) '2y' # now select 1-st (id=0) section between zeros section b1 aa 0 'x' 0 plot b1(:,1) b1(:,0) 'bo' # next, select 3-d (id=2) section between zeros section b3 aa 2 'x' 0 plot b3(:,1) b3(:,0) 'gs' # finally, select 2-nd (id=-2) section from the end section b4 aa -2 'x' 0 plot b4(:,1) b4(:,0) 'r#o'
C++ code:
void smgl_section(mglGraph *gr) { gr->SubPlot(1,1,0,"<_"); if(big!=3) gr->Title("Section&Join sample"); gr->Axis(); gr->Box(); gr->Line(mglPoint(-1,0),mglPoint(1,0),"h:"); // first lets demonstrate 'join' mglData aa(11), a1(3), a2(15); gr->Fill(aa,"x^2"); gr->Fill(a1,"-x"); gr->Fill(a2,"x^3"); aa.Join(a1); aa.Join(a2); // add x-coordinate mglData xx(aa.nx); gr->Fill(xx,"x"); aa.Join(xx); gr->Plot(aa.SubData(-1,1), aa.SubData(-1,0), "2y"); // now select 1-st (id=0) section between zeros mglData b1(aa.Section(0,'x',0)); gr->Plot(b1.SubData(-1,1), b1.SubData(-1,0), "bo"); // next, select 3-d (id=2) section between zeros mglData b2(aa.Section(2,'x',0)); gr->Plot(b2.SubData(-1,1), b2.SubData(-1,0), "gs"); // finally, select 2-nd (id=-2) section from the end mglData b3(aa.Section(-2,'x',0)); gr->Plot(b3.SubData(-1,1), b3.SubData(-1,0), "r#o"); }