Function definitions are not permitted in this context

  • Follow


Hi all,
May I know what is wrong with my code? When i run the code, error message 'Function definitions are not permitted in this context.' 

function [avgmin,avgtime,avgfunevals]=bressloff_forrester
rand('state',0)
for i=1:5
tic
[x(i),fmin(i),flag,details]=fmincon(@onevar,rand,[],[],[],[],0.01,0.99);
time(i)=toc;
evals(i)=details.funcCount;
end
avgmin=mean(fmin);
avgtime=mean(time);
avgfunevals=mean(evals);

Thanks! Your help is very much appreciated! 
 
0
Reply Dong 2/11/2011 5:09:04 PM


"Dong " <danielcn0812@gmail.com> wrote in message 
news:ij3qfg$ems$1@fred.mathworks.com...
> Hi all,
> May I know what is wrong with my code? When i run the code, error message 
> 'Function definitions are not permitted in this context.'
> function [avgmin,avgtime,avgfunevals]=bressloff_forrester
> rand('state',0)
> for i=1:5
> tic
> [x(i),fmin(i),flag,details]=fmincon(@onevar,rand,[],[],[],[],0.01,0.99);
> time(i)=toc;
> evals(i)=details.funcCount;
> end
> avgmin=mean(fmin);
> avgtime=mean(time);
> avgfunevals=mean(evals);
>
> Thanks! Your help is very much appreciated!

You can only define functions in function files; you can't define them in 
script files or at the command line.

You also cannot define a function (even a nested function) inside an IF 
statement, a FOR or WHILE loop, or a SWITCH/CASE statement.

Without seeing what else is in the file in which you store this function, 
there's no way to be more specific in describing how to resolve the problem 
than this.  If this doesn't provide you with enough information to determine 
how to fix the problem on your own, post to the newsgroup the context for 
this function (what's around it in the file.)

-- 
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com 

0
Reply Steven_Lord 2/11/2011 6:00:21 PM


1 Replies
1223 Views

(page loaded in 0.028 seconds)

Similiar Articles:













7/24/2012 12:29:53 AM


Reply: