Matlab function errors while using loop

  • MATLAB
  • Thread starter adeeyo
  • Start date
  • #1
20
0

Main Question or Discussion Point

Hi,

Please assist,

I write this matlab function and receive the error below

function f=myfunn(z,x,K,L1,L2,phi)
for c=1:3
f=z(c)-(x(2,c).*K(c).*L1)-(x(1,c).*phi(2,c).*L2)./phi(1,c);
end

function f=myfunn(z,x,K,L1,L2,phi)
|
Error: Function definitions are not permitted in this context.

Please assist me on how to go about it.

Thanks
adeeyo
 

Answers and Replies

  • #2
8
0
To define your own functions you must save them in .m files, not just type them into the command line.

To create a new function, go to File -> New -> Function and you will get a shell for a new function. If you want to start completely from scratch, you can go to File -> New -> Script.

Once you've done that, write your function and save it (the praxis is to name the .m file the same as the function inside, i.e. yours would be myfunn.m) and you will be able to call it from the command line (or scripts, or other functions) by calling it as you would any other function in MATLAB.
 

Related Threads on Matlab function errors while using loop

Replies
1
Views
17K
Replies
1
Views
3K
Replies
1
Views
6K
Replies
1
Views
2K
Replies
2
Views
2K
Replies
3
Views
7K
Replies
1
Views
3K
  • Last Post
Replies
7
Views
2K
  • Last Post
Replies
2
Views
6K
  • Last Post
Replies
2
Views
792
Top