create macros with graphical functions -凯发k8网页登录

main content

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™.

  1. create a matlab function with a graphical output. for this example, create a function named mysurf.m.

    function mysurf
    surf(peaks);
  2. 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.

  1. install and start the function wizard in microsoft excel. for details, see .

  2. click add. select the function mysurf in the functions for class mysurfclass box.

  3. click add. the function properties dialog box appears.

  4. 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.

  5. in the execute functions area of the function wizard control panel, click execute. the graphical output for mysurf appears in a separate window.

  6. 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.

  1. in the function wizard control panel, label the macro by entering mysurf in the macro name field of the create macros area.

  2. if desired, change the default value in the store macro in field.

  3. click create macro.

  4. 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.

  1. 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
  2. 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.

  1. install and start the function wizard in microsoft excel. for details, see .

  2. click add. select the function myerror in the functions for class myerrorclass box.

  3. click add. the function properties dialog box appears.

  4. add an argument with an input value of -1 to myerror.

    1. on the inputs tab, click set input data. the input data for in dialog box appears.

    2. select value and enter -1.

    3. click done.

  5. define the output of myerror — in this case, choose any empty spreadsheet cell.

    1. navigate to the outputs tab and click set output data. the output data for out dialog box appears.

    2. select range and select a spreadsheet cell value, c1, for example. the range field is automatically populated with sheet1!$c$1.

    3. 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 test myerror, deactivate these functions by selecting them and clicking deactivate.

  6. click execute. the following dialog box is displayed.

save and execute macro

create a macro to display your error message on demand.

  1. in the function wizard control panel, label the macro by entering myerror in the macro name field of the create macros area.

  2. if desired, change the default value in the store macro in field.

  3. click create macro.

  4. for details on executing macros, see .

网站地图