Can I include functions from another .m-file in my application?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi I'm making an application with the GUIDE-tool and the local callbacks are beginning to add upp to a pretty long file. I would like to group functions together and put them in a separeate file or at least hide all of them at once. Can this be done? Some programming languages lets you put include-statements in the beginning of the file. I'd like something like this in matlab.
4 Kommentare
Adam
am 31 Aug. 2016
If they literally all do the same thing you know you can point multiple editbox callbacks at the same function I assume? You don't have to have a 1-1 mapping between edit boxes and their callbacks, you just need to edit the 'Callback' property of all edit boxes to be the same function.
Stephen23
am 31 Aug. 2016
Bearbeitet: Stephen23
am 31 Aug. 2016
@Fredrik Zachrisson: "Having all these callback functions that all do the same thing with different parameters in the same file gets a bit cumbersome."
So don't have lots of callback functions: just write one function, and call that from every uicontrol. You can even call it with some parameters or other arguments, however you need to. This will likely be much simpler to write and maintain than replicating the same code into lots of functions.
Antworten (1)
Adam
am 31 Aug. 2016
Bearbeitet: Adam
am 31 Aug. 2016
You can include functions from any file that is on your path. Only 1 externally accessible function per file though if you aren't using a class. No need for include files, they will be found if they are on the path.
2 Kommentare
Adam
am 31 Aug. 2016
1 function per file can be annoying sometimes, but you tend to get use to it, especially if you just put them all in one folder or even a package folder. It is neater than putting them all in the GUIDE file and especially, of course, if you want re-usability of any of the functions outside of the GUIDE application.
Personally I do 90% of my programming in classes nowadays, but they do have a learning curve. Less so if you just do the basics with them though.
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!