Error Message: Function definitions are not permitted in this context
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
ES
el 5 de Jul. de 2014
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 comentarios
Image Analyst
el 5 de Jul. de 2014
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 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!