main content

generate and deploy a matlab app with simapptemplate for a model -凯发k8网页登录

this example shows you how to use the simulink.compiler.genapp function to generate a matlab® app for a model, that is deployable. typically when a simulink® model is functionally complete, it is often used to run multiple simulations different input and parameter values. to try simulations for your model with different input and parameter values, you can generate a matlab app. you can also deploy this generated app for use outside of matlab.

this example illustrates the use of simulink.compiler.genapp function to generate a starter app for the model f14, using the generated app to tune the parameters of the model and simulate it, and customizing the app in the matlab app designer.

open the model

the simulink.compiler.example.appgeneration command loads the example project on your path. this project contains all the files required for this example including the model. open the model f14.

simulink.compiler.example.appgeneration;
open_system('f14')

generate a matlab app for the model

use the simulink.compiler.genapp function to generate an app for the f14 model. running the simulink.compiler.genapp function with the model name as an argument generates an app named f14app. simulink compiler™ uses a default template to generate the app. the generated app provides an ability to tune the parameters and simulate the model for which the app is generated. the generated app also provides the plot of the simulation results. all the files are generated into the f14app directory.

to generate the app, the saveformat for the output data must be dataset or structure with time. to change saveformat for the f14 model, in the modelling tab of the simulink toolstrip, go to model settings. in the data import/export pane, change format to dataset.

simulink.compiler.genapp('f14', 'appname', 'f14app','template', 'simapptemplate');

after generating the app, click simulate to simulate the app.

along with the app, the following artifacts are generated :

  • f14app.mlapp file -- this file contains the code for the generated app. open this file in app designer for editing.

  • files starting with the default prefix -- functions returning default values used by the app such as, model name, model image aspect ratio, model image file, and input mat-file name.

  • model image, ( f14app_image.svg ) -- image of the simulink model.

  • inputs used in the simulation ( f14app_inputs.mat ) -- mat file containing all the inputs that are used in the simulation of the model.

  • app labels file setlabels.m -- file specifying label contents.

  • default simulink logo ( simulinklogo.png ) -- file used as a placeholder for the model image.

  • pragma.m directives file -- file used by simulink compiler to generate the deployable app.

  • set of matlab functions as m-files -- files that the app uses to control user interface of the app.

compile and deploy the generated app

you can use the matlab app designer to compile and deploy the app. you can also use deploytool. for more information on compiling and deploying with app designer, see , and .

in this example, we compile the app, with the mcc command followed by the app name.

mcc -m f14app

customize the generated app

you can also customize the generated app. to customize the app, use the app designer. the generated app f14 is generic, but it allows you to easily customize it in the app designer. in this section, we are going to replace the one axis in the generated app with two axes. open the generated app in the app designer.

appdesigner('f14app');

the idea of customization is to replace the axes component with two axes components. to get two axes components, use a grid with two rows and one column and placing the two components in the grid cells (the customized app, f14customapp is included as a part of this example project file for your reference). you can follow:

  1. in design view, select and delete the default axes component.

  2. go to component library on the left side of the window. from the component library, drag and drop a grid layout component under the containers section in place of the removed axes component. in component browser on the right, on the inspection tab under the grid layout, update columnwidth and rowheight properties to '1x' and '1x,1x', respectively. this updates the grid to have two vertical cells. drag two axes components from the common section in component library and place them in the two grid cells.

  3. the external input references to uiaxes (the original axes component) have to be updated to uiaxes2. if you added the top axes first, uiaxes refers to logged signals and uiaxes2 to external inputs. you can check by switching to design view and verifying which axes gets the focus when the component is selected in component browser.

  4. now find and replace these occurrences in the code view. using the find & replace dialog, replace uiaxes with uiaxes2 or additions. once you complete the replacements, add the following line code to the cbksimulate(app, event) function. after the line for uiaxes: app.simulationhelper.userinterface.cleargridandlegend(app.uiaxes2).

  5. save the app.

use the modified app to simulate the model

now that you have modified the app to show two axes, you can use that app to simulate the model. you can then compile and deploy the app. to simulate the app, click load input mat-file and choose the externalinputs.mat file to attach an external input signal to inport 1 of the f14 model. this activates the external input drop down and displays the loaded signal, signal.randomstickposition in the list box under the drop down. select the loaded signal to display in the bottom axes component. click simulate. after the simulation completes, the two axes components update. you can observe the effect of the loaded input signal on the logged signals in the top axes.

网站地图