Is it possible to make an app after you have written a large program?

조회 수: 5 (최근 30일)
Muazma Ali
Muazma Ali 2023년 2월 21일
답변: Rik 2023년 2월 21일
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
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
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
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.

카테고리

Help CenterFile 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!

Translated by