Why do I get the error undefined function?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all,
My code for some reason says that my second function undefined but I can clearly see that it is defined. Please help! Thanks!
-Charles
댓글 수: 0
답변 (1개)
Walter Roberson
2020년 7월 13일
Your function github_Network_construction does not call your function github_Distribution_Ana .
Typically, only the first function in a file can be called from outside the file. You should probably move github_Distribution_Ana into its own file.
댓글 수: 2
Walter Roberson
2020년 7월 13일
Read through Function Precedence Order,
and take special note that
4. Local functions within the current file
only applies when one function is calling another in the same file. If github_Network_construction called github_Distribution_Ana then precedence 4 would apply.
But github_Network_construction does not call github_Distribution_Ana . So when you try to invoke github_Distribution_Ana from outside of twoFunc.m then the rule that would potentially be active would be
10. Functions in the current folder
but that only applies when there is a file with the same name as the function being invoked. Which there is not -- there is a file named twoFunc.m so twoFunc() can be invoked. There is no way to say from outside, "call the github_Distribution_Ana that is inside twoFunc.m" . Only the first function in a file (that is not a class definition) has a public interface: the other functions in the file are private to the first function in the file.
Therefore if you want to invoke github_Distribution_Ana from outside of github_Network_construction then you will need to move the code for github_Distribution_Ana into its own file, github_Distribution_Ana.m
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!