Matlab function errors while using loop

  • MATLAB
  • Thread starter adeeyo
  • Start date
  • #1
adeeyo
20
0
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
Malle
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.
 

Suggested for: Matlab function errors while using loop

Replies
1
Views
741
Replies
6
Views
1K
Replies
1
Views
737
Replies
6
Views
288
  • Last Post
Replies
6
Views
125
Replies
2
Views
785
Replies
0
Views
405
Replies
10
Views
1K
Replies
3
Views
2K
Replies
0
Views
393
Top