This example shows how to create a standalone user interface running on a Windows computer that interacts with a real-time application using the MATLAB API.
Click here to open the model:
The model consists of a sine wave signal source, the output of which is filtered by a Discrete Filter. The model monitors the performance of the digital filter and compares it with theoretical results from the Bode plot of the filter transfer function. The frequency of the signal and the filter coefficients are defined by workspace variables that are created during model load.
model = 'dApplicationDeploymentExample'; open_system(model);
The model is configured to build a real-time application for the default Simulink Real-Time target computer but not to automatically download the application to the target computer after building. Instead, we load it using the user interface.
### Starting Simulink Real-Time build procedure for model: dApplicationDeploymentExample ### Generated code for 'dApplicationDeploymentExample' is up to date because no structural, parameter or code replacement library changes were found. ### Successful completion of build procedure for model: dApplicationDeploymentExample ### Download process is disabled.
When we deploy a Simulink Real-Time function, we assume that the target computer has been correctly set up and is running the Simulink Real-Time kernel. We also expect that the Windows computer is able to communicate with the target computer over a reliable TCP/IP network.
We create the user interface using GUIDE. The specific tasks that it implements are:
Connect to target machine
Start and stop application
Tune a parameter
Monitor signals via a host scope
Integrate MATLAB data analysis with the Simulink Real-Time functions
The example consists of the following:
In the top section, you enter the target IP address and port that will be used when you click 'Connect'. These should match the settings used when you set up the target computer. Once connected, you can download the real-time application to the target computer and start or stop it using the corresponding buttons.
The MATLAB figure on the left displays the Bode magnitude plot of the system calculated in MATLAB from the numerator and denominator coefficients of the discrete filter.
The 'System Response Plot' displays the filtered output signal acquired from the target computer using a host scope. The signal is plotted in blue and the expected maximum and minimum value of the signal is plotted in red. The expected value is calculated from the theoretically obtained Bode magnitude plot.
The 'Frequency' slider allows you to vary the input signal frequency for the real-time application. Every time the slider is changed, a blue '*' indicates the magnitude gain of the discrete filter calculated from the signal values obtained from the target computer.
You use the following MATLAB Compiler command to create a standalone executable from the MATLAB file ApplicationDeploymentExampleGUI.m and the related figure ApplicationDeploymentExampleGUI.fig.
Note: To avoid issues with the generated EXE, copy ApplicationDeploymentExampleGUI.m and ApplicationDeploymentExampleGUI.fig to a temporary directory outside the MATLAB installation location, change directory to that location and then execute the following command.
mcc -m ApplicationDeploymentExampleGUI.m ApplicationDeploymentExampleGUI.fig
You can run the executable on a Windows computer different from the development computer. You must first install the MATLAB Compiler Runtime (MCR). Make sure that the MCR exists on the Windows PATH so that the generated application can find it. More information about distributing the application is present in the README file that is created by the MCC command. The standalone application can be invoked at the Windows command prompt by executing:
If you run the application on the same Windows computer as MATLAB, exit MATLAB before running the executable.