| Contents | Index |
| On this page… |
|---|
What Can the Function Wizard Do for Me? Installation of the Function Wizard Workflow Selection for MATLAB Functions Ready for Deployment Defining Functions Ready to Execute |
End User
| Role | Knowledge Base | Responsibilities |
|
|
|
|
If your MATLAB function is ready to be deployed and you have already built your add-in and COM component with the Deployment Tool, follow this workflow to incorporate your built COM component into Microsoft Excel using the Function Wizard. To follow the workflow in this section effectively, you must already be running the Magic Square example in Getting Started.
The Function Wizard also allows you to iteratively test, develop, and debug your MATLAB function. Using this end-to-end workflow assumes you are still be in the process of developing your MATLAB function for deployment. See End-to-End Deployment of a MATLAB Function Using the Function Wizard for complete instructions for this workflow.
See Choosing the Appropriate Workflow for further details.
Key Tasks for the End User
| Task | Reference |
|---|---|
| 1. Install the Function Wizard. | Installation of the Function Wizard |
| 2. Start the Function Wizard. | Function Wizard Start-Up |
| 3. Select the option to incorporate your built COM component into Microsoft Excel. | Workflow Selection for MATLAB Functions Ready for Deployment |
| 4. Define the new MATLAB function you want to prototype by adding it to the Function Wizard and establishing input and output ranges. | Defining Functions Ready to Execute |
| 5. Test your MATLAB function by executing it with the Function Wizard. | Function Execution |
| 6. Create a macro. | Macro Creation |
| 7. Execute the macro you created using the Function Wizard. | Macro Execution |
| 8. Optionally inspect or modify the Microsoft Visual Basic code you generated with the COM component. Optionally, attach the macro you created to a GUI button. | Microsoft Visual Basic Code Access (Optional Advanced Task) |
The Function Wizard enables you to pass Microsoft Excel (Excel 2000 or later) worksheet values to a compiled MATLAB model and then return model output to a cell or range of cells in the worksheet.
The Function Wizard provides an intuitive interface to Excel worksheets. You do not need previous knowledge of Microsoft Visual Basic for Applications (VBA) programming.
The Function Wizard reflects any changes that you make in the worksheets, such as range selections. You also use the Function Wizard to control the placement and output of data from MATLAB functions to the worksheets.
Before you can use the Function Wizard, you must first install it as an add-in that is accessible from Microsoft Excel.
After you install the Function Wizard, the entry MATLAB Functions appears as an available Microsoft Excel add-in button.
Start Microsoft Excel if it is not already running.
Click the Office Button (
)
and select Excel Options.
In the left pane of the Excel Options dialog box, click Add-Ins.
In the right pane of the Excel Options dialog box, select Excel Add-ins from the Manage drop-down box.
Click Go.
Click Browse. Navigate to install_root\toolbox\matlabxl\matlabxl\arch and select FunctionWizard2007.xlam. Click OK.
In the Excel Add-Ins dialog box, verify that the entry MATLAB® Builder™ EX Function Wizard is selected. Click OK.
Click the File tab.
On the left navigation pane, select Options.
In the Excel Options dialog box, on the left navigation pane, select Add-Ins.
In the Manage drop-down, select Excel Add-Ins, and click Go.
In the Add-Ins dialog box, click Browse.
Browse to install_root/toolbox/matlabxl/matlabxl/arch, and select FunctionWizard2007.xlam. Click OK.
In the Excel Add-Ins dialog, verify that the entry MATLAB® Builder™ EX Function Wizard is selected. Click OK.
The Home tab of the Microsoft Office Ribbon should now contain the Function Wizard tile. See The Home Tab of the Microsoft Office Ribbon with Function Wizard Installed.
If the Function Wizard was previously installed, MATLAB® Builder™ EX Function Wizard appears in the list. Select the item, and click OK.
If the Function Wizard was not previously installed, click Browse and navigate to install_root\toolbox\matlabxl\matlabxl folder. Select FunctionWizard.xla. Click OK to proceed.
Start the Function Wizard in one of the following ways. When the wizard has initialized, the Function Wizard Start Page dialog box displays.
In Microsoft Excel, on the Microsoft Office ribbon, on the Home tab, select MATLAB Functions.
The Home Tab of the Microsoft Office Ribbon with Function Wizard Installed

The Function Wizard Start Page Dialog Box

After you have installed and started the Function Wizard, do the following:
From the Function Wizard Start Page, select the option I want to incorporate MATLAB Component Files Into Microsoft Excel .
Click OK. The Function Wizard Control Panel opens.
The Function Wizard Control Panel for Working with MATLAB Functions Ready for Deployment

Define the function you want to execute to the Function Wizard. Click Add in the Set Up Functions area of the Function Wizard Control Panel. The MATLAB Components dialog box opens.
In the Available Components area of the MATLAB Components dialog box, select the name of your component (xlmagic) from the drop-down box.
Select the function you want to execute (mymagic) from the box labeled Functions for Class xlmagic.
Click Add. The Function Properties dialog box opens.
Define input argument properties as follows.
On the Input tab, click Set Input Data. The Input Data for n dialog box opens.

Specify a Range or Value by selecting the appropriate option and entering the value. If the argument refers to a structure array (struct), select the option Argument is a Struct Array. See Working with Struct Arrays for information on assigning ranges and values to fields in a struct array.
Caution Avoid selecting ranges using arrow keys. If you must use arrow keys to select ranges, apply the necessary fix from the Microsoft site: http://support.microsoft.com/kb/291110. |
Click Done.
Tip To specify how MATLAB Builder EX handles blank cells (or cells containing no data), see Empty Cell Value Control. |
Define output argument properties as follows.
On the Output tab, click Set Output Data. The Output Data for y dialog box appears, where y is the name of the output variable you are defining properties of.

Specify a Range. Alternately, select a range of cells on your Excel sheet; the range will be entered for you in the Range field.
Caution Avoid selecting ranges using arrow keys. If you must use arrow keys to select ranges, apply the necessary fix from the Microsoft site: http://support.microsoft.com/kb/291110. |
Select Auto Resize if it is not already selected.
Click Done in the Output Data for y dialog box.
Click Done in the Function Properties dialog box.

mymagic now appears in the Active Functions list of the Function Wizard Control Panel.
You can specify how MATLAB Builder EX processes empty cells, allowing you to assign undefined or unrepresented (NaN, for example) data values to them.
To specify how to handle empty cells, do the following.
Click Options in the Input Data for N dialog box.
Click the Treat Missing Data As drop-down box.
Specify either Zero or NaN (Not a Number), depending on how you want to handle empty cells.
To assign ranges to fields in a struct array, do the following:
If you have not already done so, select Argument is a MATLAB Structure Array in the Input Data for n dialog box and click Done.

The Input Data for Structure Array Argument n dialog box opens.

The Function Wizard supports struct arrays organized in the following manner:
Vector struct arrays in element-by-element organization (input and output)
Two-dimensional struct arrays in element-by-element organization (input and output)
In the Input Data for Structure Array Argument n dialog box, click Add to add fields for each of your struct array arguments. The Field for Structure Array Argument dialog box opens.
In the Field for Argument dialog box, do the following:
In the Name field, define the field name. The Name you specify must match the name of your MATLAB function.
Specify the Range for the field.
Caution Avoid selecting ranges using arrow keys. If you must use arrow keys to select ranges, apply the necessary fix from the Microsoft site: http://support.microsoft.com/kb/291110. |
Click Done.
How Structure Arrays are Supported. MATLAB Builder EX supports one and two-dimensional MATLAB structure arrays.
The product converts data passed into structure arrays in element-by-element organization. If you need to work with structure arrays in plane organization, first define the function to use structure arrays in element-by-element organization as the function's inputs and outputs. Then, convert structure arrays in MATLAB code from element-by-element to plane organization. See MATLAB Programming Fundamentals for more information about all MATLAB data types, including structures.
Deploying Structure Arrays as Inputs and Outputs. If you are a MATLAB programmer and want to deploy a MATLAB function with structure arrays as input or output arguments, build Microsoft Excel macros using the Function Wizard and pass them (with the Excel Add-In and COM component) to the end users. If you can't do this, let your end users know:
Which arguments are structure arrays
Field names of the structure arrays
Using Macros with Struct Arrays. The macro generation feature of MATLAB Builder EX works with struct arrays as input or output arguments. See Macro Creation if you have a MATLAB function you are ready to deploy. See Microsoft Excel Add-in and Macro Creation Using the Function Wizard if you are using the Function Wizard to create your MATLAB function from scratch. See Choosing the Appropriate Workflow for more information on both workflows.
In the Execute Functions area of the Function Wizard Control Panel, click Execute to run mymagic. Cells A1:E5 on the Excel sheet are automatically populated with the output of mymagic (a Magic Square of dimension 5).

Continuing the example, create a Microsoft Excel macro using the Function Wizard Control Panel:
In the Create Macros area of the control panel, enter mymagic in the Macro Name field.
Select the location of where to store the macro in the Store Macro drop-down box.
Enter a brief description of the macro's functionality in the Description field.
Click Create Macro.
A macro is created in the current Excel workbook.
Run the macro you created in Macro Creation by doing one of the following, after first clearing cells A1:E5 (which contain the output of the Magic Square function you ran in Function Execution).
Tip You may need to enable the proper security settings before running macros in Microsoft Excel. For information about macro permissions and error messages occuring from executing macros, see the Troubleshooting appendix. |
In Microsoft Excel, click View > Macros > View Macros.
Select mymagic from the Macro name drop-down box.
Click Run. Cells A1:E5 on the Excel sheet are automatically populated with the output of mymagic (a Magic Square of dimension 5).
In Microsoft Excel, click Tools > Macro > Macros.
Select mymagic from the Macro name drop-down box.
Click Run. Cells A1:E5 on the Excel sheet are automatically populated with the output of mymagic (a Magic Square of dimension 5).
Optionally, you may want to access the Visual Basic code or modify it, depending on your programming expertise or the availability of an Excel developer. If so, follow these steps.
From the Excel main window, open the Microsoft Visual Basic editor by doing one of the following. select Tools > Macro > Visual Basic Editor.
Click Developer > Visual Basic.
When the Visual Basic Editor opens, in the Project - VBAProject window, double-click to expand VBAProject (mymagic.xls).
Expand the Modules folder and double-click the Matlab Macros module.
This opens the VB Code window with the code for this project.
Click Tools > Macro > Visual Basic Editor.
When the Visual Basic Editor opens, in the Project - VBAProject window, double-click to expand VBAProject (mymagic.xls).
Expand the Modules folder and double-click the Matlab Macros module.
This opens the VB Code window with the code for this project.
To attach the macro to a GUI button, do the following:
Click Developer > Insert.
From the Form Controls menu, select the Button (Form Control) icon.
In the Assign Macros dialog box, select the macro you want to assign the GUI button to, and click OK.
Attaching a Macro to a Button

| If you want to... | See... |
|---|---|
| MATLAB Code Deployment |
| See more examples about building add-ins and COM components | Microsoft Excel Add-in Creation, Function Execution, and Deployment |
| Learn how to customize and integrate the COM component you built by modifying the Microsoft Visual Basic code | Microsoft Excel Add-in Integration |
![]() | The Function Wizard | End-to-End Deployment of a MATLAB Function Using the Function Wizard | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |