1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab function errors while using loop

  1. May 16, 2012 #1
    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
     
  2. jcsd
  3. May 16, 2012 #2
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matlab function errors while using loop
  1. Error function (Replies: 5)

Loading...