Function definitions are not permitted at the prompt or in scripts
조회 수: 4 (최근 30일)
이전 댓글 표시
Can't we embed function on our script? Must be at different one and just call them?
댓글 수: 2
Stephen23
2017년 9월 17일
편집: Stephen23
2017년 9월 17일
"Function definitions are not permitted at the prompt or in scripts"
The message seems quite clear to me: your version of MATLAB does not let you define a function inside a script, or in the command prompt. From version R2016b it is possible to define a function in a script.
답변 (2개)
Christoph F.
2017년 9월 18일
편집: Walter Roberson
2017년 9월 18일
You can use anonymous functions from the command line (or in a script). Compared to named functions, they are quite limited, though.
Example:
myfun = @(x) x.^3-2*x.^2+x-1
myfun(0:5)
댓글 수: 0
Jan
2017년 9월 18일
Can't we embed function on our script?
Yes. Defining functions in script files was introduced in 2016b. If you have an older version, this does not work - exactly as the message tells you.
Must be at different one and just call them?
Yes. Or do not use a script file at all, but a function. In function files, the definition of subfunctions is allowed.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!