create macros with graphical functions
the create macro that displays graphical output example shows you how to create an add-in and macro using a function that displays graphical output. for an example that uses a matlab function that displays a dialog box, see create macro that displays error message.
create macro that displays graphical output
create an add-in and macro using a function that displays graphical output.
create add-in using function with graphical output
build your com component and add-in with matlab® compiler™.
create a matlab function with a graphical output. for this example, create a function named
mysurf.m
.function mysurf surf(peaks);
build the excel® add-in using the
mysurf
function with the library compiler app or .for example, if you are using
compiler.build.exceladdin
, type:buildresults = compiler.build.exceladdin('mysurf.m', ... 'generatevisualbasicfile','on');
for more details, see the instructions in create excel add-in from matlab.
create graphical macro using function wizard
note
for complete function wizard workflows, see .
create a macro that executes a graphical function on a microsoft® excel spreadsheet using the function wizard.
install and start the function wizard in microsoft excel. for details, see .
click add. select the function mysurf in the functions for class mysurfclass box.
click add. the function properties dialog box appears.
click done. since
mysurf.m
does not have any inputs or outputs, there is no need to specify properties.the function wizard control panel appears with
mysurf
selected in the list of active functions.in the execute functions area of the function wizard control panel, click execute. the graphical output for
mysurf
appears in a separate window.try interacting with the generated figure. for example, try dragging the figure window or inserting color bars and legends using the toolbar.
save and execute macro
once you are satisfied that your macro is usable, save the macro to execute it at your convenience.
in the function wizard control panel, label the macro by entering
mysurf
in the macro name field of the create macros area.if desired, change the default value in the store macro in field.
click create macro.
for details on executing macros, see . when the macro runs, you should see output similar to the surf peaks image above.
create macro that displays error message
create an add-in and macro using a function that displays an error message dialog box.
create add-in using function with dialog box
build your com component and add-in with matlab compiler.
create a matlab function that displays a dialog box. for this example, create a function named
myerror.m
.function out = myerror(in) if (in < 0) error('negative input not expected'); else out = sqrt(in); end
build the excel add-in using the
myerror
function with the library compiler app or .for example, if you are using
compiler.build.exceladdin
, type:buildresults = compiler.build.exceladdin('myerror.m', ... 'generatevisualbasicfile','on');
for more details, see the instructions in create excel add-in from matlab.
create macro using function wizard
set arguments for the function using the function wizard.
install and start the function wizard in microsoft excel. for details, see .
click add. select the function
myerror
in the functions for class myerrorclass box.click add. the function properties dialog box appears.
add an argument with an input value of -1 to
myerror
.on the inputs tab, click set input data. the input data for in dialog box appears.
select value and enter
-1
.click done.
define the output of
myerror
— in this case, choose any empty spreadsheet cell.navigate to the outputs tab and click set output data. the output data for out dialog box appears.
select range and select a spreadsheet cell value,
c1
, for example. the range field is automatically populated withsheet1!$c$1
.click done. the function wizard control panel appears with
myerror
selected in the list of active functions.tip
if you have functions besides
myerror
listed in the active functions list that you don't want to execute when you testmyerror
, deactivate these functions by selecting them and clicking deactivate.
click execute. the following dialog box is displayed.
save and execute macro
create a macro to display your error message on demand.
in the function wizard control panel, label the macro by entering
myerror
in the macro name field of the create macros area.if desired, change the default value in the store macro in field.
click create macro.
for details on executing macros, see .