MATLAB Answers

Package and class folders are not supported in app designer?

15 views (last 30 days)
abblah abblah
abblah abblah on 15 Mar 2020
Edited: J. Alex Lee on 19 Apr 2020
Should the *.mlapp files be in the MATLAB root folder or path? why app file can not be in the package and class folders such as +ui and @myapp folder?
In other words, how can we define multiple methods in separate files according to @myapp class using app designer?
writing all methods in the app designer editor is not rational in developing big applications.
Note that with exporting the mfile version from the app designer, package and class folders are supported but if any changes in the user interface be required,
the app designer drag and drop environment can not be used and adding new component should be done manually by code :((

  2 Comments

Mohammad Sami
Mohammad Sami on 16 Mar 2020
The best work around I have found is to use app designer purely for UI. For callbacks you can just call external functions. These can then be managed as code files outside of app designer.
J. Alex Lee
J. Alex Lee on 16 Mar 2020
+1 Mohammad's comment...but only problem is if you want your callbacks to actually be app methods, in which case you could make an app method which is a wrapper to your external function. But you still can't really control access. It's probably a moot point if your intention is to deploy as stand-alone.
Another down side of exporting as .m file is if you want to publish to a web app, I don't think it will be possible anymore.

Sign in to comment.

Accepted Answer

Arthur Roué
Arthur Roué on 16 Mar 2020
Edited: Arthur Roué on 16 Mar 2020
You can create a class folder @MyApp with the file MyApp.mlapp as constructor. Then you can create methods in separate files.

  5 Comments

Show 2 older comments
J. Alex Lee
J. Alex Lee on 17 Mar 2020
Oh, I was trying to use the "run" button. I got it to work now too.
Regarding item 3:
You could still leave the callback undefined in the appdesigner, and manually set the callback to an externally defined method in the startupfcn.
Another oddity is that for this to work, you don't even need to declare the method within a methods block in the .mlapp, although if you do, it seems you can still use the attributes as usual.
Is this all documented somewhere? Googling didn't help me...
Arthur Roué
Arthur Roué on 17 Mar 2020
By default, a method in a separate will be a public one. You can change the scope by writing the function prototype in the *.mlapp in the desired section. For instance :
methods (Static)
% A static function defined in another file
[out1, out2] = ajouterAsterisque(arg1, arg2)
end
You can also defined private function in a subfolder private of your folder class.
J. Alex Lee
J. Alex Lee on 19 Apr 2020
If you want to compile an mlapp into a web app, you need to create the web app project from the main Matlab menu; if you try to "share web" from within app designer, it will fail, I think because of the @ symbol in the class folde rname; it gives you an error about project name.

Sign in to comment.

More Answers (0)