[ADMB Users] data manipulation

dave fournier davef at otter-rsch.com
Mon Sep 20 13:16:39 PDT 2010


To deal with data all read in at one time it would be useful to have
a function which extracts multiple columns at the same time.




  dmatrix column(const dmatrix& m,int i,int j)
   {
     if (i < j )
     {
       cerr << " Invalid matrix columns specified in "
         "dmatrix column(_CONST dmatrix& m,int i,int j)\n values specified "
         "were " << i << " and " << j << "\n";
       ad_exit(1);
     }
     if (j < m.colmin() || j > m.colmax())
     {
       cerr << " Invalid matrix column specified in "
         "dmatrix column(_CONST dmatrix& m,int i,int j)\n value specified "
         "was " << j << " valid range is " << m.colmin() <<
         " to " << m.colmax() << "\n";
       ad_exit(1);
     }
     if (i < m.colmin() || i > m.colmax())
     {
       cerr << " Invalid matrix column specified in "
         "dmatrix column(_CONST dmatrix& m,int,int j)\n value specified "
         "was " << i << " valid range is " << m.colmin() <<
         " to " << m.colmax() << "\n";
       ad_exit(1);
     }
     int cmax=j-i+1;
     int mmin=m.rowmin();
     int mmax=m.rowmax();
     dmatrix tmp(mmin,mmax,1,cmax);

     for (int ii=mmin; ii<=mmax; ii++)
     {
       tmp(ii)=m(ii)(i,j).shift(1);
     }
     return(tmp);
}


another version using an ivector to pick diffeent columns would also be 
userful.

  dmatrix column(const dmatrix& m,const ivector & ind);



More information about the Users mailing list