How to Develop a Model Class for your Data and Algorithms | Modular Apps in MATLAB, Part 2 - MATLAB
Video Player is loading.
Current Time 0:00
Duration 3:50
Loaded: 4.28%
Stream Type LIVE
Remaining Time 3:50
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 3:50

    How to Develop a Model Class for your Data and Algorithms | Modular Apps in MATLAB, Part 2

    From the series: Modular Apps in MATLAB

    Learn how to develop a model class for the data and algorithms used by your MATLAB® App. Separating your algorithms and data management enables easy unit testing and keeps critical code stable and accessible.

    Published: 13 Jun 2022

    In this series we're teaching modularization techniques to efficiently develop advanced applications in MATLAB and App Designer. Modularization will enable you to develop apps that are scalable, robust, testable, and well-organized. In our previous video, we introduced the idea of data models and views. In this segment, we will show you how to develop a data model.

    Let's start with a simplified portion of the app we showed in the previous video, visualizing a stack of medical imagery. To store the data, we have a model class called MRI_Model. The properties block stores the data or state of the MRI_Model class.

    An instance of this class contains a matrix of image intensity values, positional coordinates, and the currently selected Z-slice in the xy plane. Any algorithms needed to process or operate on that data are functions, also called methods of the class.

    Placing your data and algorithms into a data model separate from the app has some important benefits. With this approach, you should be able to execute your workflow from the MATLAB command line outside of an app. This modularity enables purely programmatic approaches. For example, to run on a server. And it also facilitates unit testing to help you verify correctness of your code.

    View components need to know when data changes, so that they can be updated. They need to look for specific change events among your entire app. For example, when image data changes, the app code can update the displayed image.

    A way to do this efficiently is by marking model properties as set observable. This allows you to create an outside MATLAB listener, which runs a callback when change events occur. Another way to indicate change is by creating an events block within the model class, which creates specific named events that outside components can listen to. The model conditions decide when that event is triggered by sending a notify command. Methods of the model class allow for external users or functions to adjust it. A callback in an app uses these methods to apply user choices to the model.

    Your model may need multiple levels of data. It is completely normal to have hierarchical data, and it can be easily represented with class objects in MATLAB. For example, a ContactList class might have an array of contact objects, each containing details of one specific contact. The address might be another nested class in the hierarchy. In a later video, we will show you how to link this data model together with the view component, so when the model is changed the view will automatically update itself.

    Data models are essential in modular development. They offer easy unit testing and keep critical code stable and accessible. In the next videos, we will show you how to build custom UI components, and then pair them with the data model.

    For more information about building apps in MATLAB check out the links in the description. There you can also find links to our training classes and consulting services in the app development space. Thank you for watching.

    Up Next:

    View full series (4 Videos)

    View more related videos