Matlab editor: the function might be unused
이전 댓글 표시
Below is the body of my code.It keeps saying that func2 might be unused.I'm not sure how to fix this...

댓글 수: 3
Chao Yin
2017년 5월 16일
u can't define an other function in one m file unless the later one has been cited by the former
Walter Roberson
2017년 5월 16일
Chao Yin: that is not correct. You can define any number of functions in the same .m file, without them needing to refer to each other. You might not be able to execute any function other than the very first unless you make special arrangements, but it is valid to define them.
Mustafa Akgül
2020년 12월 9일
How can I define
채택된 답변
추가 답변 (1개)
Image Analyst
2014년 10월 1일
func2 was never used, never called, in func1. You just assigned y to some equation, which happened to be similar (but not the same) equation as in func2. You never said
y=fun2(x)
anywhere in your main function, func1.
You also need the line
global G;
inside func2 if func2 is to use the same value of G that func1 had. If you do that, and have the G=50 line, then it will also become 50 once you get back inside func1.
댓글 수: 2
Julia
2014년 10월 2일
I think the task of this homework is to understand how the given functions work. And that it is intended that func2 does not use the global variable G.
Image Analyst
2014년 10월 2일
편집: Image Analyst
2014년 10월 2일
If it's not global, then she must pass it in via the input argument list. That's perhaps the best way. Other ways of getting the same G inside func2() (if you need the same G in there) are discussed in the FAQ http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F. Of course maybe they don't want that and want you to see how the G in func2() is not the same value as the one in func1().
The homework problem instructions pass in G as part of an expression which is evaluated so it's not really passed in. Even if it were, it's overwritten with a value of 50, but since it's not global and not passed out, the 50 value won't be seen outside of func2().
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
