Error Message: Function definitions are not permitted in this context
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi I'm new enough to matlab. I am having a problem with running my code and was wondering if anyone can give me advice. Whenever I run it and error message appears saying ' Function definitions are not permitted in this context '. This is the code:
function f=path(mu,lambda,Y0,sigma,N)
dW=sigma*randn(N-1,1);
ARpath=zeros(N,1);
ARpath(1)=Y0;
for i=2:N
ARpath(i)=ARpath(i-1)+mu+lambda*ARpath(i-1)+dW(i-1);
end
f=ARpath;
end
댓글 수: 0
답변 (2개)
ES
2014년 7월 5일
You cannot write a function definition on Matlab Command Window.
Open editor and paste your code in a file and save it and run it from the editor or command window.
ALSO: path is a inbuilt function. If you create a function by an inbuilt function name, the inbuilt will be overridden. take care..
댓글 수: 0
Image Analyst
2014년 7월 5일
Chances are you have a script and function in the same m-file. You can't do that - they all have to be functions. For example in test.m, you cannot do this
f1 = myPathFunction; % Call the function from a script.
function f =m yPathFunction(mu,lambda,Y0,sigma,N)
% Code goes here.
However if test is a function, it's fine:
function test()
f1 = myPathFunction; % Call the function from inside another function.
function f =m yPathFunction(mu,lambda,Y0,sigma,N)
% Code goes here.
Also notice that I did not use the reserved, built-in function "path" for the name of the functions. You should not do that either. Change the name of your function. It's very risky/dangerous to change the definition of built-in functions.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!