Troubleshooting Multiple Inputs in Matlab Functions: Common Errors and Solutions

  • MATLAB
  • Thread starter PieceORock
  • Start date
  • Tags
    Matlab
In summary, There seems to be a misunderstanding on how to properly call the function my_func1 and the function Trap. The input arguments are being called incorrectly, causing the error message to appear. It is important to make sure the function is being called with the correct number of input arguments.
  • #1
PieceORock
2
0
I am having problems putting multiple inputs into a function file. This is what I have.

function y = my_func1(r ,V)
y=6.28.*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
 
Physics news on Phys.org
  • #2
I don't see any problem with that function. Are you sure your calling the function properly?
 
  • #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?
 
  • #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.
 
  • #5
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.
 

Related to Troubleshooting Multiple Inputs in Matlab Functions: Common Errors and Solutions

1. What are the most common errors encountered when troubleshooting multiple inputs in Matlab functions?

Some of the most common errors include: mismatched number of inputs, incorrect data types for inputs, missing inputs, and input variables not being defined within the function.

2. How do I fix a mismatched number of inputs error?

To fix this error, ensure that the number of inputs specified in the function definition matches the number of inputs being passed in when calling the function. If you are using variable inputs, make sure they are being properly defined and passed in.

3. What should I do if I am getting an error related to incorrect data types for inputs?

If you are getting this error, check the data types of the inputs being passed into the function. Make sure they match the expected data types specified in the function definition. If necessary, you can use the class() function to check the data type of a variable.

4. Why am I getting a "missing input" error?

This error occurs when one or more required inputs are not being passed in when the function is called. Check the function definition to make sure all necessary inputs are specified, and make sure they are being properly defined and passed in.

5. How can I avoid common errors when troubleshooting multiple inputs in Matlab functions?

To avoid common errors, make sure to carefully define and document your function inputs. Use variable inputs or optional inputs if needed. Additionally, thoroughly test your function with different input values to catch any potential errors.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
820
Back
Top