Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab inputs question

  1. Mar 31, 2005 #1
    I am having problems putting multiple inputs into a function file. This is what I have.

    function y = my_func1(r ,V)

    When I try to use this function, it says:

    ??? Input argument "V" is undefined.

    Switching r and V gives the same error, but it is always the second variable that throws the error. If anybody knows if I am putting this in wrong, please let me know
  2. jcsd
  3. Mar 31, 2005 #2


    User Avatar
    Staff Emeritus

    I don't see any problem with that function. Are you sure your calling the function properly?
  4. Mar 31, 2005 #3
    There's nothing wrong with that function. (I assume you're saving it as my_func1.m).

    It works fine for me as long as I call it with 2 arguments, i.e
    > my_func1(2,3)

    I can reproduce your error message exactly if I call it with only 1 argument. You wouldn't be doing that by any chance, would you?
  5. Mar 31, 2005 #4
    I don't know if I'm calling it incorrectly. I made two arrays, one for r and one for V like this r=[1 2 3] and V=[1 2 3] in the command window. Then I am called another function with the line I = Trap('my_func1', 0, 1, 1)
    where the numbers are just inputs to another function.
  6. Apr 1, 2005 #5


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    By writing the line

    I=Trap('my_func1', 0, 1, 1)

    You are not calling the function my_func1.

    You are calling the function Trap with the inputs being the string (not the function) 'my_func1' and then three input variables.

    Inside the function Trap, you will probably find a line which calls whatever the input string is. That function call most likely only has one input variable which is why you are getting undefined input variables.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Matlab inputs question