Why do I get the error undefined function?
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 13 Jul 2020
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 Comments
Walter Roberson
on 13 Jul 2020
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
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!