Why can I not return matrices to Excel cells using MATLAB Builder for Excel 1.2.7 (R2006b)?

1 view (last 30 days)
I am able to use the following function directly from a cell using MATLAB Builder for Excel 1.2.7 (R2006b):
function out = one(in)
out = 2 * in;
I enter the following formula in an Excel cell:
=one(3)
and this successfully evaluates to 6.
However, I cannot return a matrix using a similar method:
function out = two(in)
out = [in 2; 3 4];
When I enter the following formula:
=two(3)
I receive the following error message: ERROR: #VALUE!

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Nov 2015
This is expected behavior for MATLAB Builder for Excel. Excel formula functions, which are embedded in worksheet cells, can only return single scalars.
Functions that return multiple arguments or matrix arguments should be called from VBA Macros as subroutine procedures. Refer to the following documentation for more information:
<http://www.mathworks.com/help/releases/R2006b/toolbox/matlabxl/ug/index.html?/help/releases/R2006b/toolbox/matlabxl/ug/f6-5594.html>
This restriction is imposed by Excel on all formula functions, and is not specific to MATLAB Builder for Excel.
For an example of how to call your functions from VBA Macros, consult the Magic Square example at
<http://www.mathworks.com/help/releases/R2006b/toolbox/matlabxl/ug/index.html?/help/releases/R2006b/toolbox/matlabxl/ug/f2-7373.html>
In some instances, you may also be able to use array functions instead of formula functions; for more information, see the Related Solution below.

More Answers (0)

Categories

Find more on Data Export to MATLAB in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2006b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!