how to define a function

조회 수: 9 (최근 30일)
Charles Kinoshita
Charles Kinoshita 2017년 7월 20일
편집: Walter Roberson 2017년 7월 21일
why do I have error message when I type
function dy = ff(t,y)
  댓글 수: 2
Charles Kinoshita
Charles Kinoshita 2017년 7월 21일
편집: Stephen23 2017년 7월 21일
but shouldn't I be able to type
>> clear
>> function yprime = bvexample(t,y)
function yprime = bvexample(t,y)
Error: Function definitions are not permitted in this context.
Steven Lord
Steven Lord 2017년 7월 21일
No. You cannot define functions by typing the text of their body at the Command Prompt. You need to write them as a function file. [If your function can be written as one statement, you could create an anonymous function handle.]

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

답변 (1개)

James Tursa
James Tursa 2017년 7월 20일
편집: James Tursa 2017년 7월 20일
If you are getting this message:
Error: Function definitions are not permitted in this context.
It means that you cannot define a function in that part of the code. E.g., you cannot define functions at the end of script files in older versions of MATLAB. So either turn your script file into a function file itself, or copy your function code to a new file (with the name ff.m).
But this is all just a guess, since you haven't told us what the error message is or shown us any code.

카테고리

Help CenterFile Exchange에서 Robotics에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by