XLL+ Class Library

Matrix layouts

The matrix argument of LinearInterp2D() was required to be an array of pointers to columns. It could have been different; it might have required:

Optional flags are available for reading matrices into these layouts.

Matrix Data Flag Layout Flag Description
Pointers Columns Array of pointers to columns
Pointers Rows Array of pointers to rows
Values Columns Continuous array of values, arranged with columns together
Values Rows Continuous array of values, arranged with rows together

As it happens, Pointers/Columns is the default layout combination, which is why we didn't have to do any extra work in the Wizard to get the right layout for LinearInterp2D(). If we need a different layout, we need to do a little more work in the wizard.

Matrix argument laid out as a continous array of values

To demonstrate the use of a different matrix layout, we are going to add a function which returns the location of the maximum value within a two-dimensional array. Add the simple function shown below to the end of Tutorial1.cpp:

#include <algorithm>

// Find location of maximum value in adValues
// adValues must be a continuous array, with columns held together
int FindMax(int cCols, int cRows, double *adValues, int* pnMaxCol, int* pnMaxRow)
{
    std::vector<double>::iterator itMax;
    double* pdEnd = adValues + (cRows * cCols);
    // Use STL algorithm to find offset of max value
    itMax = std::max_element(adValues, pdEnd);
    if (itMax == pdEnd)
        return 0;
    // Translate offset to coords
    *pnMaxRow = (itMax - adValues) % cRows;
    *pnMaxCol = (itMax - adValues) / cRows;
    return 1;
}

As you can see, this function takes advantage of the STL max_element algorithm to do all the hard work. The important things to note, as far as our add-in function is concerned, are:

Next, we'll use the XLL+ Function Wizard to apply these layout rules.

Next: Using the Edit Argument Dialog >>