I am a novice with App Designer, so if someone have any problems with anything I have written here, fill free to comment and help me learn :)
I recently came into the same problem - I wanted to create a small UI, that ask user to perform some task (multi-image labelling, while playing a video in order to help them). I wanted to use App Designer, as building UI programmatically only is a pain. Ideally, users can:
- Write their own functions that can used the UI produced labels.
- Run the UI from command window, and continue using cm if they want (non-modal window).
I found 2 possible solutions:
More general one: have the uifigure "CloseRequestFcn" save to mat file any output you want. Then you can wait for UI to close (when calling from function, use "waitfor"), and load this file. Pros: Easy to do, keep all of App Designer abilities. Saving any hard collected user input in not necessarily a bad idea. Cons: This is somewhat "poofing" variables into existence, similar to the option @Mario Malic did not recommend above. Also great way to save unneeded files (especially if you will save this output later, after more analysis). May be slow.
Less general: save wanted outputs as properties, then make sure your app object "live" after the uifigure was closed. However I found out that something in matlab.apps.AppBase class make sure the app object is deleted when its associated uifigure is closed, and I haven’t found simple workaround for that.
So I exported my app to .m file (one of the options under "save"), and changed it to be a "handle" class -
inside the app Constructor remove the "registerApp", switch the function "runStartupFcn" with a simple call to your "startupFcn".In the createComponents function, any component callback switch from:
createCallbackFcn(app, @myCallBack, true);
More changes might be needed in case your app use more App Designer abilities that I'm not familiar with.
Pros: now your app is an object with graphic fields instead of being dependent on the figure (Why this dependency is needed anyway?). No need to save any variable - it is all in the class, no variable was "poofed" into later code. Cons: for more complex app may take a little longer (not very time consuming in any case I think). You may lose some of App Designer due to this change (I am not familiar with App Designer enough to say).
I think all in all, the first option in better, even if the secound is more "nice looking".