How to properly structure code in appdesigner?
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Inception
el 15 de Mayo de 2022
Comentada: Jon
el 23 de Mayo de 2022
Hi.
Assume having a complex GUI with dozens of private functions. What is the best way to split the code into separate files? How can I tell MATLAB that there is a private function, but the implementation of that function is done in a separate file?
2 comentarios
Kevin Holly
el 17 de Mayo de 2022
As for your second question, if the function file is located within your path, MATLAB will find it when you call it. Call the function as you normally would. If the file is not within your current path, you can use addpath to add it to your path. Let me know if I misunderstood your question.
Respuesta aceptada
Jon
el 17 de Mayo de 2022
I have been taking an approach where I try to keep the code in the app designer very simple and then define a class which provides all the complex functionality for the callbacks, accessing data etc.
So for example I define a handle class which I call GuiManager. I then assign an instance, guiManager, of this class as a property of the app.
All of the complicated functionality is then coded as methods of the GuiManager class. Within app designer if I want to call one of these functions, for example myMethod, e.g. within a callback, I just reference it as app.guiManager.myMethod(arg1,arg2,...)
Are you able to understand the approach I've just outlined? If you want further details please ask.
3 comentarios
Jon
el 19 de Mayo de 2022
I just coded up a small example similar to yours. It seems to work fine directly setting the label using a function in an external file. Please put both of these files in the same directory (or set the path to the directory where giveFive is) and try.
One thing you may want to check. The errors for the app designer may appear in the app designer window not on the command line. Maybe you have some small error in your code.
Jon
el 23 de Mayo de 2022
Glad you got it working, sounds like you had the right idea all along. I haven't thought about it too much, but I think there are probably some tradeoffs between the convenience of supplying the external function the entire app object, and the risks that this allows the external function access to too much. A little like a global variable. If it unintentionally does something to parts it shouldn't be touching it could be hard to trace what went wrong. So maybe sometimes it is better to just send the external program the data it needs and return a result and then let the app use the data.
Más respuestas (1)
Inception
el 18 de Mayo de 2022
Editada: Inception
el 18 de Mayo de 2022
2 comentarios
Walter Roberson
el 18 de Mayo de 2022
app is handle class. You can define get and set operations and put access restrictions on them.
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!