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!