Why do I get the error undefined function?

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

답변 (1개)

Walter Roberson
Walter Roberson 2020년 7월 13일

0 개 추천

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

Charles sun
Charles sun 2020년 7월 13일
I think you misinterpreted my question. My program has two functions. The first function reads in a text file and outputs two variables. Then, I want to use those two variables in the second function. The following link has two datsets the first of which is what I'm using: https://figshare.com/collections/Inter-urban_interactions_of_mobility_via_cellular_position_tracking_in_the_southeast_Songliao_Basin_Northeast_China/4226183/4
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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

질문:

2020년 7월 13일

댓글:

2020년 7월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by