Quickie, global variables and sub functions.
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I have a primary function set with 12 global variables I want the sub-functions to use, they are only double constants held during a loop.
Apart from being typing lazy (copy/past) and prob bad programming, is there any programming problem or reason why I should not declare a global variable in a sub-function that is not used?
Thanks
AD
댓글 수: 0
채택된 답변
Paulo Silva
2011년 12월 6일
The variables should be passed to the functions as arguments, using global variables always introduce problems that are hard to debug, also if you declare a variable on a function you can access the same variable in every sub-function of that function.
Now for your question, besides the use of global variables and that sub-function that's not used?! I don't see any other problem
댓글 수: 3
Paulo Silva
2011년 12월 6일
Sean you are correct, thanks, I always confuse them, there's a nice video tutorial from Doug Hull http://blogs.mathworks.com/videos/2011/09/20/managing-code-in-matlab-nested-sub-functions
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Function Creation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!