Example #1
0
        public NumericMatrix <V> extract(SpreadSheetRange <AI1, AI2> range)
        {
            // Slice a matrix
            AI1 rmin = range.upperLeft.first;
            AI2 cmin = range.upperLeft.second;

            AI1 rmax = range.lowerRight.first;
            AI2 cmax = range.lowerRight.second;

            int Rmin = r[rmin]; int Rmax = r[rmax];
            int Cmin = c[cmin]; int Cmax = c[cmax];

            // Now must find the integer indices corresponding to these
            NumericMatrix <V> result = new NumericMatrix <V>(Rmax - Rmin + 1, Cmax - Cmin + 1, Rmin, Cmin);

            for (int ri = Rmin; ri <= Rmax; ri++)
            {
                for (int ci = Cmin; ci <= Cmax; ci++)
                {
                    result[ri, ci] = mat[ri, ci];
                }
            }

            return(result);
        }
Example #2
0
        // Change values in some range
        public void modify(SpreadSheetRange <AI1, AI2> range, FunctionEval <V> function)
        { // Using a delegate to change the values in a range!
          // Objective is to iterate in a range and apply a function to each
          // element in that range

            AI1 rmin = range.upperLeft.first;
            AI2 cmin = range.upperLeft.second;

            AI1 rmax = range.lowerRight.first;
            AI2 cmax = range.lowerRight.second;

            int Rmin = r[rmin]; int Rmax = r[rmax];
            int Cmin = c[cmin]; int Cmax = c[cmax];


            // Now must find the integer indices corresponding to these
            V d;

            for (int ri = Rmin; ri <= Rmax; ri++)
            {
                for (int ci = Cmin; ci <= Cmax; ci++)
                {
                    d = mat[ri, ci];
                    function(ref d);
                    mat[ri, ci] = d;
                }
            }
        }