Search code examples
matlabmatlab-guidematlab-app-designer

Creating a MATLAB GUI for an infinite looping script


I'm currently working on a MATLAB script call manager.m . This script contains an infinite loop that monitors a communication thread for incoming commands.

I would like to a create a status window for this program such that a user knows that it is function properly (e.g. indicate good connection status, current state, etc.). Note that I do not want a user to be able to input any information from this GUI, it's only purpose is to be a display.

I went ahead and created a simple GUI using the App Designer program. I converted my manager.m script into a function that is called during the GUI start-up.

However, I'm running into an issue that since the function contains an infinite loop, closing the GUI does not actually kill the function. Essentially the function just keeps looping/executing.

After several failed attempts to fix the problem, I feel like I'm not using the GUI App Designer as it would typically be used. It seems like apps are responsible for the looping aspect, and simply monitor user inputs for execute events when necessary. By adding my own infinite loop into a manager function, it seems to be complicating everything.

So my question: if I want to create a status display for an infinite looping MATLAB script, what is the preferred method for doing this?


Solution

  • After thinking about it a little more, I realized that the MATLAB App Designer could just be used as a "designer". I went ahead and created my display screen, and then clicked on the "View Code" option.

    If you scroll down through the code, you can find section that initializes all of the user-interface components. You can simply copy this code and paste it into your own script.

    This method allows you to use the MATLAB drag-and-drop designer to generate the user interface code, while allowing you control your own program flow through your script.