Is it possible to make an app after you have written a large program?
3 次查看(过去 30 天)
显示 更早的评论
Hi! I have made a program in matlab and just started to make the app in matlab app designer but I am wondering whether I have done it in the right way by making a program at first and then making the app..
3 个评论
dpb
2023-2-21
If the code you have written works with just a set of inputs of some sort passed into it as a function, then it's essentially trivial to follow @Jan's suggestion above; you now just develop an appropriate UI to use to call the main function of your program instead of running it from the command line.
Little functional code need (nor should) be in the .mlapp file; it can (and should) reside in its own m-files and is just called by the callback function(s) in the GUI.
dpb
2023-2-21
To amplify on the comment above -- the bulk of the code in the .mlapp file is stuff for housekeeping and the top-level callback functions.
The niceties of having the app keep its memory of where user left controls states and input file locations, etc., etc., ... is a lot of the typical "housekeeping" code that belongs there.
Then the callbacks don't need to do much of the work; just make sure the inputs are verified before calling the actual working code routines and then return the results needed to be available for other functions.
The biggest difference here is that you may need to share the various pieces of data computed by your app in global structure variables so the other callback functions can have access to those results if everything isn't done all in one function or one main function that calls all the workers sequentially before it returns to the UI.
回答(1 个)
Rik
2023-2-21
In my personal opinion, a GUI should only be an interface to your function (that is after what the I stands for). That means it should only provide a convenient way to collect inputs and settings from your user and present progress/results to the user.
WIth that in mind it makes perfect sense to write your function first as a command line interface (CLI), and then create a wrapper around it that provides a graphical user interface (GUI).
If you want practical advice about how to approach creating a GUI in Matlab, you might want to have a look at this thread. I personally don't use AppDesigner, but most advice is interchangeable if you follow the design filosophy that Jan and dpb also already mentioned.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!