GUI: Call external functions or define them within a GUI?
5 ビュー (過去 30 日間)
古いコメントを表示
Hi, I'd like to know if calling an external function in a GUI is considerably slower than defining the function within the GUI and then calling it. I don't like to have my GUI stuffed with functions when I could simply put them in a .m file in the GUIs folder. Are there any disadvantages to this approach though?
Thanks!
0 件のコメント
採用された回答
David Barry
2016 年 12 月 14 日
The short answer is no there is no performance issue here and splitting up functionality into separate functions should be encouraged, especially if they are reusable components. Having a single GUI function quickly becomes out of hand so you should always spend time upfront thinking about your software architecture before you start writing code.
その他の回答 (1 件)
Image Analyst
2016 年 12 月 15 日
I guess it's a matter of preference. I prefer a lot of functions in my GUI m-file, unless they're general purpose utilities to be used by a lot of programs. But if it's a function that is used only by that GUI, I just put them all in the same file. That way I can easily go to the function by using the GoTo drop down list on the tool ribbon, and all the functions are listed all the time, unlike if your functions are in files that you have not opened yet. And if I type control-D to go to a function, it also leaves me in the same editor window, which cuts down on the number of editor windows (tabs) that I have open (less clutter). I go to so many functions when I'm editing a bug program (dozens) that if every time I went to one it opened a new editor window and threw me over there it would get confusing. Bookmarks I had set in the main program don't work anymore when I'm in another editor file, etc. And if you have more than about 10 editor windows open you can no longer see them all and you have to go over to the little down arrow to select the window you need. It's just a cluttered pain. Searching is a little easier if everything is in one file since you can type control-F instead of control-shift-f which takes extra dexterity or the use of two hands instead of one. So I find it easier to put them all in the same m-file. For me, it's easier to have one file, one editor window, one set of bookmarks, easier searching, less cluttered interface, etc.
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!