XLL+ Class Library

COper::ToMatrix() Example

//{{XLP_SRC(MyMatrixMult)
    // NOTE - the FunctionWizard will add and remove mapping code here.
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(MyMatrixMult, "RPP", "MyMatrixMult", "X,Y", 
    "User Defined", "Multiply two matrices", "First matrix\000Sec"
    "ond matrix\000", "\0\0", 1)

extern "C" __declspec( dllexport )
LPXLOPER MyMatrixMult(const COper* lpopX, const COper* lpopY)
{
    CXlOper xloResult;
//}}XLP_SRC

    BOOL       bOk = TRUE;
    CString    strError;

    // Read each matrix
    xlp::matrix<double> matX;
    if ( bOk && !(bOk = lpopX->ToMatrix(matX, &strError)) )
        strError = "Error in X: " + strError;

    xlp::matrix<double> matY;
    if ( bOk && !(bOk = lpopY->ToMatrix(matY, &strError)) )
        strError = "Error in Y: " + strError;

    // Check their sizes
    if ( bOk && !(bOk = (matX.rows() == matY.rows())
                     && (matX.cols() == matY.cols())) )
        strError = "Error: X and Y must be the same size";

    // Dismiss input errors now
    if ( !bOk )
    {
        xloResult = strError;
        return xloResult.Ret();
    }

    // Calculate the result
    size_t i, j;
    xlp::matrix<double> matOut;
    matOut.resize(matX.rows(), matX.cols());
    for ( i = 0; i < matX.rows(); i++ )
        for ( j = 0; j < matX.cols(); j++ )
            matOut.at(i, j) = matX.at(i, j) * matY.at(i, j);
    
    xloResult = matOut;
    return xloResult.Ret();
}

Uses

COper::ToMatrix | matrix<T> | matrix<T>::resize | matrix<T>::at