The function is now almost complete, and ready for building and testing.
It needs one more piece of work: we need to constrain the size of the
matrix Z to be the same width as X and the same height as Y.
Our core function,
LinearInterp2D() assumes that these
constraints have been satisfied.
Launch the Argument Editor for Z. There are several ways to do this:
In the Argument Editor, select the Matrix tab:
In the Constraints group box, use the "Height is equal to" and "Width is equal to" combo-boxes to set the constraints:
The result of these changes will be to create two new
These will be set to the sizes of X and Y respectively when X and Y are
evaluated. They they will then be checked against the height and width
of Z respectively.
// Named bounds long sizeOfX = -1; long sizeOfY = -1; // Validate and translate inputs XlReadVector(*X_op, X, L"X", XLA_TRUNC_ONEMPTY|XLA_TRUNC_ONBLANK, &sizeOfX); XlReadVector(*Y_op, Y, L"Y", XLA_TRUNC_ONEMPTY|XLA_TRUNC_ONBLANK, &sizeOfY); XlReadMatrix(*Z_op, mtx_adapter(Z), L"Z", XLA_TRUNC_ONEMPTY| XLA_TRUNC_ONBLANK, &sizeOfY, 0, &sizeOfX);
If either constraint fails, then an exception will be thrown, and
an appropriate message will be returned to Excel, e.g.:
Expected 5 rows for Z.
You can see the constraints displayed in the Function Wizard:
They will also show up in the Properties window when you select X, Y or Z in the ToolWindow:
Build and run the add-in.
Try out the validation code. If you are using English as your language, you can get errors such as the following:
#ERROR: Expected 3 columns in Z #ERROR: Expected 3 rows in Z #ERROR: Expected number for Z[1,4]