{"id":3766,"date":"2026-07-13T09:29:18","date_gmt":"2026-07-13T13:29:18","guid":{"rendered":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/?p=3766"},"modified":"2026-07-13T09:29:18","modified_gmt":"2026-07-13T13:29:18","slug":"developing-a-mass-spring-damper-app-using-mvc-architecture-and-simulink","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/2026\/07\/13\/developing-a-mass-spring-damper-app-using-mvc-architecture-and-simulink\/","title":{"rendered":"Developing a Mass Spring Damper App using MVC Architecture and Simulink"},"content":{"rendered":"<table style=\"background-color: #e2f0ff\">\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 120px;padding: 3px;vertical-align: middle\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft wp-image-832\" src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2024\/02\/kdeeley-150x150.jpg\" alt=\"\" width=\"110\" height=\"110\" data-wp-editing=\"1\" \/><\/td>\r\n<td style=\"vertical-align: middle;padding: 3px\"><strong>Guest Writers\r\n<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/2987674\" target=\"_blank\" rel=\"noopener\">Ken Deeley<\/a>\r\n<\/strong>\r\n<div class=\"content\">\r\n<div class=\"SectionBlock first active\">\r\n<div class=\"SD57BF6401\">Ken is an application engineer in Cambridge, UK, supporting MathWorks users with their technical computing projects. Ken joined the MathWorks customer training team in 2011 after research work in mathematics with applications to motion planning for autonomous guided vehicle (AGV) robotics. Ken specializes in software development, machine learning, and financial applications, with a particular focus on graphics and app development. He enjoys training MathWorks users on best practices, working with customers on consulting projects, and capturing common customer workflows and requirements to inform future MathWorks development activities.<\/div>\r\n<\/div>\r\n<\/div><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<table style=\"background-color: #e2f0ff\">\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 120px;padding: 3px;vertical-align: middle\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft wp-image-832\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2026\/07\/MariaBedran.jpg\" alt=\"\" width=\"110\" height=\"110\" \/><\/td>\r\n<td style=\"vertical-align: middle;padding: 3px\"><strong><a href=\"https:\/\/www.linkedin.com\/in\/mariabedran\/\" target=\"_blank\" rel=\"noopener\">Maria Bedran<\/a>\r\n<\/strong>\r\n<div class=\"content\">\r\n<div class=\"SectionBlock first active\">\r\n<div class=\"SD57BF6401\">Maria joined MathWorks' Cambridge office, in 2022,where she moved after her studies in Lyon, France. She started her journey in the Engineering Development Group, where she first got exposed to Advanced App development in MATLAB. She then joined the customer training team in 2025. Maria now specializes in Control System Design in Simulink. Outside of work, Maria enjoys dancing, hiking and playing the piano.<\/div>\r\n<\/div>\r\n<\/div><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<div class=\"rtcContent\">\r\n<div style=\"margin-bottom: 20px;padding-bottom: 4px\">\r\n<div><\/div>\r\n<div style=\"margin: 0px;padding: 10px 0px 10px 5px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: bold;text-align: start\"><span class=\"_richTextNode\" style=\"font-weight: bold\">Table of Contents<\/span><\/div>\r\n<div style=\"margin: -1px 0px 0px;padding: 10px 0px 10px 7px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: start\"><a href=\"#TMP_2471\"><span class=\"_richTextNode\">Overview\r\n<\/span><\/a><a href=\"#TMP_2a34\"><span class=\"_richTextNode\">MVC for an App Using a Simulink Model\r\n<\/span><\/a> \u00a0\u00a0 \u00a0<a href=\"#TMP_2028\"><span class=\"_richTextNode\">Autogenerated Apps\r\n<\/span><\/a> <a href=\"#TMP_99b0\"><span class=\"_richTextNode\">\u00a0 \u00a0 Hand-Coded Modular Apps\r\n<\/span><\/a><a href=\"#TMP_31a2\"><span class=\"_richTextNode\">Integrating a Simulation Object in the App\r\n<\/span><\/a>\u00a0 \u00a0<a href=\"#TMP_2c4d\"><span class=\"_richTextNode\">Overview\r\n<\/span><\/a>\u00a0 \u00a0<a href=\"#TMP_6073\"><span class=\"_richTextNode\">Working with Simulation Objects\r\n<\/span><\/a><a href=\"#TMP_5fde\"><span class=\"_richTextNode\">Binding UI Components to Simulation Signals and Variables\r\n<\/span><\/a> \u00a0 \u00a0 <a href=\"#TMP_523b\"><span class=\"_richTextNode\">Overview\r\n<\/span><\/a> \u00a0 \u00a0 <a href=\"#TMP_9ad5\"><span class=\"_richTextNode\">Views\r\n<\/span><\/a> \u00a0\u00a0 \u00a0<a href=\"#TMP_362e\"><span class=\"_richTextNode\">Controllers\r\n<\/span><\/a><a href=\"#TMP_12b8\"><span class=\"_richTextNode\">Events and Listeners\r\n<\/span><\/a> \u00a0 \u00a0 <a href=\"#TMP_1c9b\"><span class=\"_richTextNode\">Simulation Status\r\n<\/span><\/a> \u00a0 \u00a0 <a href=\"#TMP_89f1\"><span class=\"_richTextNode\">Model Variables\r\n<\/span><\/a><a href=\"#TMP_9e7d\"><span class=\"_richTextNode\">Web App Deployment\r\n<\/span><\/a><a href=\"#TMP_7e8c\"><span class=\"_richTextNode\">Summary<\/span><\/a><\/div>\r\n<\/div>\r\n<h2 id=\"TMP_2471\" style=\"margin: 3px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\" style=\"font-weight: bold\">Overview<\/span><\/h2>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">In this article we'll show how to deploy a simple web app for running a Simulink model. The app supports updating the model parameters dynamically as the simulation is running. This process represents a workflow for sharing your Simulink model with others, preserving the IP contained in your model, but simultaneously allowing your end users to interact with the model by modifying its tunable parameters during run time.<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">We'll be discussing the following products and concepts:<\/span><\/div>\r\n<ul style=\"margin: 10px 0px 20px;padding-left: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-size: 14px\">\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><a href=\"https:\/\/www.mathworks.com\/products\/simulink-compiler.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">Simulink Compiler<\/span><\/a><\/li>\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><a href=\"https:\/\/www.mathworks.com\/products\/matlab-web-app-server.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">Web apps<\/span><\/a><\/li>\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><span class=\"_richTextNode\">The <\/span><a href=\"https:\/\/github.com\/mathworks\/matlab-model-view-controller\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">model-view-controller<\/span><\/a><span class=\"_richTextNode\"> software architecture pattern for app development<\/span><\/li>\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><span class=\"_richTextNode\">The <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/bind.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">binding mechanism<\/span><\/a><span class=\"_richTextNode\"> for connecting app components to simulation signals and variables<\/span><\/li>\r\n<\/ul>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">The Simulink model we'll work with in this article is a modified version of the mass-spring-damper example from the <\/span><a href=\"https:\/\/www.mathworks.com\/help\/slcompiler\/index.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">Simulink Compiler documentation<\/span><\/a><span class=\"_richTextNode\">.<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">open_system(<span style=\"color: #a709f5\">\"MassSpringDamperModel\"<\/span>);<\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-3768 alignnone\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2026\/07\/MassSpringDamperAppUsingMVC.mlx-07-10-26_1.png\" alt=\"\" width=\"584\" height=\"326\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">This article builds on the ideas introduced by Robert Philbrick in a previous article <\/span><a href=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/2024\/05\/15\/build-simulink-apps-with-app-designer\/\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">Build Simulink Apps with App Designer<\/span><\/a><span class=\"_richTextNode\">. Robert's article covers the <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/referencelist.html?type=function&amp;category=create-app-designer-apps-to-control-simulations&amp;s_tid=CRUX_topnav\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">Simulink UI components<\/span><\/a><span class=\"_richTextNode\"> introduced in R2024a and the process for developing an App Designer app wrapping the Simulink model using these components. Material for this article can be accessed in <\/span><a href=\"https:\/\/github.com\/MATLAB-Graphics-and-App-Building\/mass-spring-damper-mvc-app\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">GitHub<\/span><\/a><span class=\"_richTextNode\">.<\/span><\/div>\r\n<h2 id=\"TMP_2a34\" style=\"margin: 3px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\" style=\"font-weight: bold\">MVC for an App Using a Simulink Model<\/span><\/h2>\r\n<h3 id=\"TMP_2028\" style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\" style=\"font-weight: bold\">Autogenerated Apps<\/span><\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">To deploy your Simulink model as a web app, it must be compatible with <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/how-the-acceleration-modes-work.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">rapid accelerator mode<\/span><\/a><span class=\"_richTextNode\">. Assuming this is the case, Simulink Compiler has a useful <\/span><a href=\"https:\/\/www.mathworks.com\/help\/slcompiler\/ref\/simulink.compiler.genapp.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">feature<\/span><\/a><span class=\"_richTextNode\"> for automatically generating a frontend:<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">simulink.compiler.genapp(<span style=\"color: #a709f5\">\"MassSpringDamperModel.slx\"<\/span>)<\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">This command automatically generates an <\/span><a href=\"https:\/\/www.mathworks.com\/products\/matlab\/app-designer.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">App Designer<\/span><\/a><span class=\"_richTextNode\"> app that you can then deploy as a web app. The resulting app visualizes the output signals from the model, and contains controls to allow you to interact with the model inputs, parameters, and initial states.<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">We can choose from a list of predefined templates for generating the App Designer app. This approach is extremely convenient and requires no expertise in app design to deploy the web app. On the other hand, the app produced by this approach is monolithic and exists in a single App Designer file, making future collaborative development and testing trickier. Further, the app would need to be regenerated if you decide to make any modifications to your Simulink model.<\/span><\/div>\r\n<h3 id=\"TMP_99b0\" style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\">Hand-Coded Modular Apps<\/span><\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">In some cases, you will want to include additional features in the web app, such as integrating with external MATLAB code or customizing the layout or appearance of the dashboard. In these cases, the automatically generated app from Simulink Compiler is a good starting point for further development. However, to avoid manually copying and pasting the code for your additional features each time you regenerate the app, we recommend taking a modular approach to application development which separates the backend (model) from the frontend (how the model is visualized and modified). A modular approach is also more suitable for larger or more complex applications.<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">Specifically, in this article we'll look at how to develop a MATLAB app for interacting with the Simulink model using the <\/span><a href=\"https:\/\/www.mathworks.com\/company\/technical-articles\/developing-matlab-apps-using-the-model-view-controller-pattern.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">MVC framework<\/span><\/a><span class=\"_richTextNode\">. Our app's layout and architecture are shown below.<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-3769 alignnone\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2026\/07\/MassSpringDamperAppUsingMVC.mlx-07-10-26_2.png\" alt=\"\" width=\"761\" height=\"445\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 775px;height: 370px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2026\/07\/MassSpringDamperAppUsingMVC.mlx-07-10-26_3.png\" alt=\"\" width=\"775\" height=\"370\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">Let's start by looking at the app's backend code - we'll need to write a model class in MATLAB that is backed by the Simulink model.<\/span><\/div>\r\n<h2 id=\"TMP_31a2\" style=\"margin: 3px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\" style=\"font-weight: bold\">Integrating a Simulation Object in the App<\/span><\/h2>\r\n<h3 id=\"TMP_2c4d\" style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\" style=\"font-weight: bold\">Overview<\/span><\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">In the app, we can change the values of the following model parameters using <\/span><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/uispinner.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\" style=\"font-family: monospace\">uispinner<\/span><\/a><span class=\"_richTextNode\"> controls:<\/span><\/div>\r\n<ul style=\"margin: 10px 0px 20px;padding-left: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-size: 14px\">\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><span class=\"_richTextNode\">The mass <\/span><span style=\"font-family: STIXGeneral-webfont, serif;font-style: italic;font-weight: 400\">m<\/span><span class=\"_richTextNode\"> (kg)<\/span><\/li>\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><span class=\"_richTextNode\">The spring stiffness <\/span><span style=\"font-family: STIXGeneral-webfont, serif;font-style: italic;font-weight: 400\">k<\/span><span class=\"_richTextNode\"> (N\/m)<\/span><\/li>\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><span class=\"_richTextNode\">The damping coefficient <\/span><span style=\"font-family: STIXGeneral-webfont, serif;font-style: italic;font-weight: 400\">b<\/span><span class=\"_richTextNode\"> (N\/m\/s)<\/span><\/li>\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><span class=\"_richTextNode\">The initial position <\/span><span style=\"vertical-align: -6px\">$ x_0 $<\/span><span class=\"_richTextNode\"> (m).<\/span><\/li>\r\n<\/ul>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">The mass, stiffness, and damping coefficient can all be changed dynamically as the simulation is running, whereas the initial position can only be changed between simulation runs. The simulation outputs are the position, velocity, and acceleration of the mass over time. The external force on the system is specified using a <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/repeatingsequencestair.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">repeating sequence stair block<\/span><\/a><span class=\"_richTextNode\"> with repeating values 0, 10, and 20 with a sample time of 10s. As the force and simulation outputs change over time, we visualize the signals in the app using <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/uitimescope.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">time scopes<\/span><\/a><span class=\"_richTextNode\">.<\/span><\/div>\r\n<h3 id=\"TMP_6073\" style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\" style=\"font-weight: bold\">Working with Simulation Objects<\/span><\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">In the MVC framework, the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Model<\/span><span class=\"_richTextNode\"> class is responsible for managing the Simulink model, providing access to the simulation data so that views can visualize it, and providing mechanisms for interacting with the Simulink model so that controllers can perform operations. <\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">To be able to change the model's inputs at run time and update the simulation automatically, we create a <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/simulink.simulation.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">s<\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">imulink.Simulation<\/span><\/a><span class=\"_richTextNode\"> object as a property of the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Model<\/span><span class=\"_richTextNode\"> class:<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">obj.Simulation = simulation(obj.SimulinkModelName);<\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">The <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">simulink.Simulation<\/span><span class=\"_richTextNode\"> object allows you to modify simulation parameters at run time without changing the underlying model. It is also deployable and supports the binding mechanism that we'll discuss shortly. <\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">Within the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Model<\/span><span class=\"_richTextNode\"> class, we use the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">simulink.Simulation<\/span><span class=\"_richTextNode\"> object in conjunction with the <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/simulink.simulationinput.setvariable.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\" style=\"font-family: monospace\">setVariable<\/span><\/a><span class=\"_richTextNode\"> function to update the model parameters:<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">setVariable(obj.Simulation, <span style=\"color: #a709f5\">\"m\"<\/span>, obj.Mass)<\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">We equip the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Model<\/span><span class=\"_richTextNode\"> class with an API for changing the Simulink model parameters via public properties:<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">classdef<\/span> Model &lt; handle<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0<span style=\"color: #0e00ff\">properties<\/span> (SetObservable)<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #008013\">% Spring stiffness - k (N\/m).<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Stiffness<span style=\"color: #a0522d\">(1, 1) double {mustBePositive, mustBeFinite}<\/span> = 100<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #008013\">% Mass - m (kg).<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Mass<span style=\"color: #a0522d\">(1, 1) double {mustBePositive, mustBeFinite}<\/span> = 10<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #008013\">\u00a0\u00a0% Damping coefficient - b (N\/m\/s).<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0DampingCoefficient<span style=\"color: #a0522d\">(1, 1) double {mustBePositive, mustBeFinite}<\/span> = 1<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #008013\">% Initial position\/displacement - x0 (m).<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0InitialPosition<span style=\"color: #a0522d\">(1, 1) double ...<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #a0522d\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{mustBeNonnegative, mustBeFinite}<\/span> = 0.5<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0<span style=\"color: #0e00ff\">end<\/span> <span style=\"color: #008013\">% properties (SetObservable)<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">end<\/span><span style=\"color: #008013\"> % classdef<\/span><\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">The <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">simulation.Simulation<\/span><span class=\"_richTextNode\"> object provides non-blocking methods <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/simulink.simulation.start.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\" style=\"font-family: monospace\">start<\/span><\/a><span class=\"_richTextNode\"> and <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/simulink.simulation.stop.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\" style=\"font-family: monospace\">stop<\/span><\/a><span class=\"_richTextNode\"> for controlling the simulation. Our model class provides simple public wrapper methods which can be invoked by application controllers.<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">function<\/span> startSimulation(obj)<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #008013\">%STARTSIMULATION Start the Simulink simulation.<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">start(obj.Simulation)<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">end<\/span> <span style=\"color: #008013\">% startSimulation<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">function<\/span> varargout = stopSimulation(obj)<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #008013\">%STOPSIMULATION Stop the Simulink simulation.<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">nargoutchk(0, 1)<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">simOut = stop(obj.Simulation);<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">if<\/span> nargout == 1<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0varargout{1} = simOut;<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">end<\/span> <span style=\"color: #008013\">% if<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">end<\/span> <span style=\"color: #008013\">% stopSimulation<\/span><\/div>\r\n<\/div>\r\n<h2 id=\"TMP_5fde\" style=\"margin: 3px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\">Binding UI Components to Simulation Signals and Variables<\/span><\/h2>\r\n<h3 id=\"TMP_523b\" style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\">Overview<\/span><\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">Starting in R2024a, a <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/bind.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">binding mechanism<\/span><\/a><span class=\"_richTextNode\"> between UI components and Simulink was introduced. With respect to view classes in the MVC framework, the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">bind<\/span><span class=\"_richTextNode\"> function allows you to link logged signals associated with a <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">simulink.Simulation<\/span><span class=\"_richTextNode\"> object to a time scope for dynamic plotting. With respect to controller classes in MVC, we use <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">bind<\/span><span class=\"_richTextNode\"> to connect the value of a UI control component (such as a spinner) to a model variable.<\/span><\/div>\r\n<h3 id=\"TMP_9ad5\" style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\">Views<\/span><\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 477px;height: 440px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2026\/07\/MassSpringDamperAppUsingMVC.mlx-07-10-26_4.png\" alt=\"\" width=\"477\" height=\"440\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">We create a view class <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">SignalView<\/span><span class=\"_richTextNode\"> to visualize the force input and position, velocity, and acceleration model outputs over time. This class maintains and updates four <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/uitimescope.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">time scopes<\/span><\/a><span class=\"_richTextNode\"> as the simulation progresses. This is achieved by binding each time scope to the corresponding logged signal in the model. For example, for the force input, the binding is constructed as follows:<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">obj.Bindings(1) = bind(obj.Model.Simulation.LoggedSignals, ...<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0<span style=\"color: #a709f5\">\u00a0\"MassSpringDamperModel\/External Force:1\"<\/span>, ...<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0obj.SignalTimeScope(1));<\/div>\r\n<\/div>\r\n<h3 id=\"TMP_362e\" style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\">Controllers<\/span><\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 561px;height: 299px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2026\/07\/MassSpringDamperAppUsingMVC.mlx-07-10-26_5.png\" alt=\"\" width=\"561\" height=\"299\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">We create a controller class <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">SimulationController<\/span><span class=\"_richTextNode\"> to start\/stop the simulation, export the simulation data, and modify the model variables. This class maintains four spinner controls to allow the end user to adjust the values of the model variables. To keep the spinner controls synchronized with the model variables, we create bindings as follows:<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">obj.Bindings(1) = bind(obj.Spinners(1), <span style=\"color: #a709f5\">\"Value\"<\/span>, ...<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0obj.Model.Simulation.TunableVariables, <span style=\"color: #a709f5\">\"m:MassSpringDamperModel\"<\/span>);<\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">This binds the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Value<\/span><span class=\"_richTextNode\"> property of the spinner with the variable <\/span><span style=\"font-family: STIXGeneral-webfont, serif;font-style: italic;font-weight: 400\">m<\/span><span class=\"_richTextNode\"> in the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">MassSpringDamperModel<\/span><span class=\"_richTextNode\">. We also use the following UI components available with Simulink:<\/span><\/div>\r\n<ul style=\"margin: 10px 0px 20px;padding-left: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-size: 14px\">\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/uisimcontrols.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\" style=\"font-family: monospace\">uisimcontrols<\/span><\/a><span class=\"_richTextNode\"> - creates the simulation controls (start\/stop)<\/span><\/li>\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/uisimprogress.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\" style=\"font-family: monospace\">uisimprogress<\/span><\/a><span class=\"_richTextNode\"> - displays the simulation progress bar<\/span><\/li>\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/uisimdatabutton.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\" style=\"font-family: monospace\">uisimdatabutton<\/span><\/a><span class=\"_richTextNode\"> - creates the button to save the simulation data<\/span><\/li>\r\n<\/ul>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">Each of these controls is connected to the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Simulation<\/span><span class=\"_richTextNode\"> object maintained by the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Model<\/span><span class=\"_richTextNode\"> class.<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">obj.StartStopControls = uisimcontrols(<span style=\"color: #a709f5\">\"Simulation\"<\/span>, obj.Model.Simulation);<\/div>\r\n<\/div>\r\n<h2 id=\"TMP_12b8\" style=\"margin: 3px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\" style=\"font-weight: bold\">Events and Listeners<\/span><\/h2>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">Events and listeners are the key features of MATLAB's class\/object system that enable separation of concerns in the MVC architecture. The model and view-controller classes are separate. They each have a specific responsibility, and the model needs to communicate changes to the views and controllers.<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">When the model modifies the data that it stores, it notifies an event. The listeners maintained by the view and controller classes will then invoke their callback function when the event is received.<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">The binding mechanism described above encapsulates some of the required communication between the model and frontend classes. However, to achieve a fully functional system we need to respond to the following situations:<\/span><\/div>\r\n<ul style=\"margin: 10px 0px 20px;padding-left: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-size: 14px\">\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><span class=\"_richTextNode\">If the simulation is running, we should disable the spinner for the initial position. This variable can only be changed between simulation runs, and not during an active simulation.<\/span><\/li>\r\n \t<li style=\"margin-left: 56px;line-height: 21px;min-height: 0px;text-align: left\"><span class=\"_richTextNode\">If another controller changes one of the model variables, the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">SimulationController<\/span><span class=\"_richTextNode\"> should display the updated parameter values in its spinner controls.<\/span><\/li>\r\n<\/ul>\r\n<h3 id=\"TMP_1c9b\" style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\" style=\"font-weight: bold\">Simulation Status<\/span><\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">The <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Model<\/span><span class=\"_richTextNode\"> class maintains the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">simulink.Simulation<\/span><span class=\"_richTextNode\"> object, which is equipped with the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">SimulationStatusChanged<\/span><span class=\"_richTextNode\"> event. The <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Simulation<\/span><span class=\"_richTextNode\"> property of the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Model<\/span><span class=\"_richTextNode\"> is publicly accessible, so in the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">SimulationController<\/span><span class=\"_richTextNode\"> class we can create the required listener as follows:<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">obj.SimulationStatusListener = listener(obj.Model.Simulation, ...<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0<span style=\"color: #a709f5\">\u00a0\"SimulationStatusChanged\"<\/span>, @obj.onSimulationStatusChanged);<\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">The listener callback updates the initial position spinner according to the simulation status.<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">function<\/span> onSimulationStatusChanged(obj, ~, ~)<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #008013\">%ONSIMULATIONSTATUSCHANGED Respond to changes in the<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #008013\">%simulation's status.<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">obj.Spinners(4).Enable = obj.Model.Simulation.Status == <span style=\"color: #a709f5\">\"inactive\"<\/span>;<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">end <span style=\"color: #008013\">% onSimulationStatusChanged<\/span><\/div>\r\n<\/div>\r\n<h3 id=\"TMP_89f1\" style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\">Model Variables<\/span><\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">The <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Model<\/span><span class=\"_richTextNode\"> class also maintains the values of the mass, stiffness, damping coefficient, and initial position. To allow frontend components to listen to changes in these parameter values, we provide these properties with the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">SetObservable<\/span><span class=\"_richTextNode\"> attribute.<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">classdef<\/span> Model &lt; handle<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0properties (SetObservable)<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #008013\">% Spring stiffness - k (N\/m).<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Stiffness<span style=\"color: #a0522d\">(1, 1) double {mustBePositive, mustBeFinite}<\/span> = 100<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0...<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0end <span style=\"color: #008013\">% properties (SetObservable)<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">end<\/span> <span style=\"color: #008013\">% classdef<\/span><\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">In the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">SimulationController<\/span><span class=\"_richTextNode\"> class, we can then create the property listeners as follows:<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">obj.ParameterListeners(1) = listener(obj.Model, <span style=\"color: #a709f5\">\"Mass\"<\/span>, <span style=\"color: #a709f5\">\"PostSet\"<\/span>, @obj.onMassChanged);<\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">The listener callbacks simply update the spinners with the new parameter values:<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">function<\/span> onMassChanged(obj, ~, ~)<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #008013\">%ONMASSCHANGED Respond to changes in the model's Mass property.<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">obj.Spinners(1).Value = obj.Model.Mass;<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">end<\/span> % onMassChanged<\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">Using the events and listeners as described ensures that communication between the app's <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Model<\/span><span class=\"_richTextNode\"> class and its frontend components is correctly synchronized.<\/span><\/div>\r\n<h2 id=\"TMP_9e7d\" style=\"margin: 3px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\">Web App Deployment<\/span><\/h2>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">To bring everything together, we have an application launcher class <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">MassSpringDamperLauncher<\/span><span class=\"_richTextNode\"> that instantiates the model and creates the views and controllers. To be deployable as a web app, we also need to create an App Designer app to create the app's main figure window (<\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">app.Figure<\/span><span class=\"_richTextNode\">) and invoke our application launcher. We do this by defining a startup function in App Designer that simply calls our application launcher by passing it the figure defined in App Designer.<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #008013\">% Code that executes after component creation<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">function<\/span> onStartup(app)<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">\u00a0\u00a0\u00a0\u00a0MassSpringDamperLauncher(app.Figure);<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">end<\/span><\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">The app can then be compiled and deployed as a web app using Simulink Compiler. We've automated this process by using an <\/span><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/overview-of-matlab-build-tool.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">automated build<\/span><\/a><span class=\"_richTextNode\"> containing a task that packages the web app using <\/span><a href=\"https:\/\/www.mathworks.com\/help\/compiler\/webapps\/compiler.build.webapparchiveoptions.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\" style=\"font-family: monospace\">compiler.build.WebAppArchiveOptions<\/span><\/a><span class=\"_richTextNode\"> and <\/span><a href=\"https:\/\/www.mathworks.com\/help\/compiler\/webapps\/compiler.build.webapparchive.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\" style=\"font-family: monospace\">compiler.build.webAppArchive<\/span><\/a><span class=\"_richTextNode\">.<\/span><\/div>\r\n<div class=\"preformatted-matlab\" style=\"margin: 10px 3px 10px 55px;padding: 10px 10px 10px 5px\">\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">function<\/span> compileTask(c)<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #008013\">% Compile the web application.<\/span><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">projectRoot = c.Plan.RootFolder;<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">appFile = fullfile(projectRoot, <span style=\"color: #a709f5\">\"tbx\"<\/span>, tbxname(),<span style=\"color: #a709f5\"> \"apps\"<\/span>, <span style=\"color: #a709f5\">\"MassSpringDamperApp.mlapp\"<\/span>);<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">simModel = fullfile(projectRoot, <span style=\"color: #a709f5\">\"tbx\"<\/span>, tbxname(),<span style=\"color: #a709f5\"> \"models\"<\/span>, <span style=\"color: #a709f5\">\"MassSpringDamperModel.slx\"<\/span>);<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">opts = compiler.build.WebAppArchiveOptions(appFile);<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">opts.AdditionalFiles = simModel;<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\">compiler.build.webAppArchive(opts);<\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><\/div>\r\n<div style=\"border-radius: 0px;padding: 0px;line-height: 15.6px;min-height: 16px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 12px\"><span style=\"color: #0e00ff\">end<\/span> <span style=\"color: #008013\">% compileTask<\/span><\/div>\r\n<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">This produces a web app archive ready for deployment. See <\/span><a href=\"https:\/\/www.mathworks.com\/help\/webappserver\/ug\/deploy-a-web-app.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">Deploy Web App<\/span><\/a><span class=\"_richTextNode\"> for details.<\/span><\/div>\r\n<h2 id=\"TMP_7e8c\" style=\"margin: 3px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\"><span class=\"_richTextNode\">Summary<\/span><\/h2>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">In this post we've seen how to integrate the <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">simulink.Simulation<\/span><span class=\"_richTextNode\"> object in a <\/span><span class=\"_richTextNode\" style=\"font-family: monospace\">Model<\/span><span class=\"_richTextNode\"> class that wraps the Simulink model. This class also provides an interface for the frontend application components to visualize the simulation output data and modify simulation parameters during runtime. In the frontend components, we've used the <\/span><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/create-app-designer-apps-to-control-simulations.html?s_tid=CRUX_lftnav\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">Simulink UI controls<\/span><\/a><span class=\"_richTextNode\"> to simplify the development of the user interface.<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span class=\"_richTextNode\">Since we've used the <\/span><a href=\"https:\/\/www.mathworks.com\/company\/technical-articles\/developing-matlab-apps-using-the-model-view-controller-pattern.html\" target=\"_blank\" rel=\"noopener\"><span class=\"_richTextNode\">MVC framework<\/span><\/a><span class=\"_richTextNode\"> to develop the application, the resulting app is modular, maintainable, testable, scales robustly as additional features are added over time, and facilitates parallel development across a wider team.<\/span><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><\/div>\r\n&nbsp;\r\n\r\n<\/div>\r\n<script type=\"text\/javascript\">\r\n{ let css = '._richTextNode {white-space: break-spaces;}';\r\nlet head = document.head || document.getElementsByTagName('head')[0];\r\nlet style = document.createElement('style');\r\nhead.appendChild(style);\r\nstyle.type = 'text\/css';\r\nif (style.styleSheet) {\r\n    style.styleSheet.cssText = css;\r\n} else {\r\n    style.appendChild(document.createTextNode(css));\r\n}\r\n\r\n\r\n}<\/script><a href=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2026\/07\/MassSpringDamperAppUsingMVC.mlx\"><button class=\"btn btn-sm btn_color_blue pull-right add_margin_10\">Download Live Script<\/button><\/a>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2026\/07\/MassSpringDamperAppUsingMVC.mlx-07-10-26_1.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>\r\n\r\n\r\n\r\nGuest Writers\r\nKen Deeley\r\n\r\n\r\n\r\nKen is an application engineer in Cambridge, UK, supporting MathWorks users with their technical computing projects. Ken joined the MathWorks customer... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/2026\/07\/13\/developing-a-mass-spring-damper-app-using-mvc-architecture-and-simulink\/\">read more >><\/a><\/p>","protected":false},"author":198,"featured_media":3768,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,11,32],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts\/3766"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/users\/198"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/comments?post=3766"}],"version-history":[{"count":7,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts\/3766\/revisions"}],"predecessor-version":[{"id":3776,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts\/3766\/revisions\/3776"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/media\/3768"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/media?parent=3766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/categories?post=3766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/tags?post=3766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}