How do I invoke my custom MATLAB function using Spreadsheet Link EX?

I would like to call a MATLAB function that I have written, directly from an Excel cell, without writing any VBA macro.

 採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日

0 投票

To call your MATLAB function from an Excel cell using Spreadsheet Link EX API, follow these steps:
1. Write your MATLAB function. For example, 'myMLFcn.m'.
2. Move your MATLAB function to one of the directories in MATLAB startup path or, add a command to one of MATLAB startup files to include your directory at startup. For example, add the following to the end of MATLABRC.M:
addpath '$MATLAB_FUNCTION_ROOT'
where $MATLAB_FUNCTION_ROOT is the directory containing your MATLAB function. This will ensure that whenever you start MATLAB, either in full desktop mode or as a COM automation server, your function will be visible.
3. If required, export the data from your spreadsheet to MATLAB using MLPutMatrix or equivalent APIs.
4. Invoke your MATLAB function 'myMLFcn' as:
=MLEvalString("[y1, y2, ...] = myMLFcn(x1, x2, ...)")
where y1, y2, ...are output arguments and x1, x2, ...are input arguments. Note that the command as invoked here assumes that x1, x2, ...already exist in MATLAB workspace.
5. If required, bring the output arguments back to the spreadsheet using MLGetMatrix or equivalent APIs.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCustomization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by