Error Message: Function definitions are not permitted in this context
조회 수: 10 (최근 30일)
이전 댓글 표시
I still new for this software so I'm not sure this error is a simple or complex error. Hope someone could give me a simple answer. Any reply would be highly appreciated.
댓글 수: 0
답변 (1개)
Geoff Hayes
2015년 10월 18일
편집: Geoff Hayes
2015년 10월 18일
Bill - this error message typically indicates that you have an m file that begins with some code outside of a function definition, and then you define a function somewhere after that code. For example, if I save the following code to an m file, I would observe the same error when I try to evaluate the code.
t = 1;
for k=14;
t = t + 1;
end
function incorrect();
From your screen capture, you show that you have defined the function Tank at line 17 of your file and so you must have done something similar to above. To fix this, you can do one of two things: save the function Tank to its own m file named Tank.m, or nest this function within a main function for the file (with the same name as the m file). For example, if your code is saved to a file names main.m you could do
function main()
% some code
% now nest Tank
function Tank()
% etc.
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!